AVQueuePlayer
アプリ内でメディアを再生するために使用しています。MPNowPlayingInfoCenter
アプリがバックグラウンドになっているときに、再生の現在のステータスを表示するために使用しようとしています。私の問題は、メディアが再生されている場合でも、再生ボタンが常に表示されることです。次のコードを使用して、現在再生中の情報を設定しています。
NSDictionary *songInfo = @{
MPMediaItemPropertyTitle: title,
MPMediaItemPropertyArtist: artist,
MPMediaItemPropertyAlbumTitle: album,
MPMediaItemPropertyPlaybackDuration: duration,
MPNowPlayingInfoPropertyPlaybackRate: @(1.0f),
MPNowPlayingInfoPropertyElapsedPlaybackTime: @(0.0f)
};
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
次のスクリーンショットからわかるように、一時停止ボタンが表示されるはずの場所に再生ボタンが表示されています。
関連する場合に備えて、AVAudioSession
カテゴリをに設定していますAVAudioSessionCategoryPlayback
。
NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
error:&sessionError];
[[AVAudioSession sharedInstance] setActive: YES error: NULL];