Search code examples
iosavqueueplayermpnowplayinginfocenter

MPNowPlayingInfoCenter showing as paused


I'm using AVQueuePlayer within my app to play some media. I'm attempting to use MPNowPlayingInfoCenter to show the current status of playback when the app is backgrounded. My issue is the play button is always showing, even when media is playing. I'm setting the now playing info via the following code:

 NSDictionary *songInfo = @{
                           MPMediaItemPropertyTitle: title,
                           MPMediaItemPropertyArtist: artist,
                           MPMediaItemPropertyAlbumTitle: album,
                           MPMediaItemPropertyPlaybackDuration: duration,
                           MPNowPlayingInfoPropertyPlaybackRate: @(1.0f),
                           MPNowPlayingInfoPropertyElapsedPlaybackTime: @(0.0f)
                           };

[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];

As you can see from the following screenshot, the play button is shown, where I'd expect to see the pause button.enter image description here

In case it's relevant, I am setting the AVAudioSession category to AVAudioSessionCategoryPlayback.

NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
                                       error:&sessionError];
[[AVAudioSession sharedInstance] setActive: YES error: NULL];

Solution

  • Perhaps a little counter-intuitive, but in order to set the play button status, and start the elapsed time incrementing is to do the following:

    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];