iphone - 是否可以在不停止 iPod 音乐的情况下播放声音?

标签 iphone ios audio ipod

是否可以在不停止 iPod 音乐的情况下在应用程序中播放声音?

现在我正在使用以下内容,但它会停止播放 iPod 音乐

soundPath =[[NSBundle mainBundle] pathForResource:@"mySound" ofType:@"mp3"];
soundURL = [NSURL fileURLWithPath:soundPath];   
mySound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil];
[mySound prepareToPlay];

然后

[mySound play];

最佳答案

是的,你可以,你可以使用下面的代码

// setup session correctly
AVAudioSession *audiosession = [AVAudioSession sharedInstance];
[audiosession setCategory:AVAudioSessionCategoryPlayback error:nil];
OSStatus propertySetError = 0;

UInt32 mixingAllow = true;
propertySetError = AudioSessionSetProperty ( kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (mixingAllow),&mixingAllow);

NSError *error = nil;
[audiosession setActive:YES error:&error];

// play sound
NSURL *url = [NSURL fileURLWithPath:filePath];
AVAudioPlayer *audioplayer = [[[AVAudioPlayer alloc] initWithContentsOfURL:url error:&;error]autorelease];

关于iphone - 是否可以在不停止 iPod 音乐的情况下播放声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11036748/

相关文章:

ios - 带有矩形角且没有箭头的弹出式当前 View Controller

iphone - 检查字典中是否存在标签

ios - UITableViewCell Segue 不工作

ios - 如何知道您的 cocoapod 安装指向哪个 pod 规范文件

安卓 Java : decoding a mp3 file and passing data into a short[] array for analysis

c - 在 MIDI 合成器中播放音符的数据结构

iphone - UICollectionView布局

ios - 如何在 iOS 中将 UILabel 的字体名称设置为 HelveticaNeue Thin?

ios - UITableViewCell 无法将标签约束到右边缘

php - 我怎样才能使麦克风声音从我的电脑上打开的网站传输到其他电脑上打开的网站?