【问题标题】:AVAudioPlayer with MPMusicPlayerController带有 MPMusicPlayerController 的 AVAudioPlayer
【发布时间】:2010-07-11 19:01:21
【问题描述】:

我在我的应用程序中使用MPMusicPlayerController 播放音乐,使用iPodMusicPlayer(也尝试过applicationMusicPlayer)。当我使用AVAudioPlayer 播放声音时,来自MPMusicPlayerController 的音乐将停止。有没有办法让MPMusicPlayerControllerAVAudioPlayer 同时播放声音?

【问题讨论】:

  • 您是否有机会将我的答案标记为正确,例如延迟 5 年? :)

标签: iphone objective-c audio avaudioplayer


【解决方案1】:

嘿,在网上找到了解决方案。

在某处写这两行,我是在 application:didFinishLaunchingWithOptions 中完成的

// Set sounds not to stop music
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];

必须承认我没有深入研究细节,但它确实有效......

祝你好运!

奥德。

【讨论】:

    【解决方案2】:

    Oded Ben Dov 的解决方案可以完成这项工作,但您可能不想更改会话类别。例如,如果您希望在屏幕锁定时继续播放音频,则需要播放类别。

    在这种情况下,您可以改为应用此类别覆盖:

    UInt32 mixWithOthers = YES;
    AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(mixWithOthers), &mixWithOthers);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-23
      • 2010-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多