我使用iPodMusicPlayer (也尝试过applicationMusicPlayer)在我的应用程序中使用MPMusicPlayerController播放音乐。当我使用AVAudioPlayer播放声音时,我的MPMusicPlayerController音乐将会停止。有没有办法让MPMusicPlayerController和AVAudioPlayer同时播放声音?
发布于 2011-02-07 04:20:21
嘿,我在网上找到了解决方案。
在应用程序中编写这两行代码:didFinishLaunchingWithOptions
// Set sounds not to stop music
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];我必须承认我没有深入研究细节,但它是有效的。
祝好运!
怪异。
发布于 2012-04-27 06:41:47
Oded Ben Dov的解决方案可以完成这项工作,但您可能不想更改会话类别。例如,如果您希望在屏幕锁定时继续播放音频,则需要“播放”类别。
在这种情况下,您可以改为应用此类别覆盖:
UInt32 mixWithOthers = YES;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(mixWithOthers), &mixWithOthers);https://stackoverflow.com/questions/3224269
复制相似问题