【问题标题】:MPNowPlayingInfoCenter always in "playing" state when playing audio throughMPNowPlayingInfoCenter 在通过播放音频时始终处于“正在播放”状态
【发布时间】:2015-04-13 03:54:26
【问题描述】:

我们开发了一个跨平台的多媒体播放器。它使用 OpenAL 播放音频。在 iOS 上,我们想使用 MPNowPlayingInfoCenter 和远程控制事件的功能。

设置当前位置,经过时间,其他轨道信息效果很好。但是,不幸的是,当按下信息中心播放器中的暂停按钮时,播放器会暂停,但暂停按钮不会改变其状态。信息中心继续显示播放没有暂停(时间标签继续计数)。

我们这样处理 UIEventSubtypeRemoteControlPause 事件:

[self.player pause]; // Pause playback

// Update MPNowPlayingInfoCenter
NSMutableDictionary *mediaInformation = [NSMutableDictionary dictionaryWithDictionary:[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo];
mediaInformation[MPNowPlayingInfoPropertyPlaybackRate] = @0.0;
mediaInformation[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @(self.player.currentTime);
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = mediaInformation;

MPNowPlayingInfoCenter 是否支持通过 OpenAL 播放音频或者我们错过了什么。

【问题讨论】:

    标签: ios objective-c audio openal audio-player


    【解决方案1】:

    我也遇到了同样的问题,结果发现毕竟和OpenAL无关,而是AVAudioSession的播放类别,看这个栈溢出帖:Is MPNowPlayingInfoCenter compatible with AVAudioPlayer?

    我使用以下代码设置了正确的类别:

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *setCategoryError = nil;
    BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
    

    我最初使用withOptions: AVAudioSessionCategoryOptionMixWithOtherssetCategory:AVAudioSessionCategoryPlayback,导致锁屏播放控件不起作用。

    【讨论】:

      猜你喜欢
      • 2014-06-28
      • 1970-01-01
      • 2013-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      相关资源
      最近更新 更多