Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell the MPNowPlayingInfoCenter wether or not the music is playing or paused?

I can't seem to make iOS show the correct play / pause button in the remote audio controls. I do receive the remote control events and set all values of the nowPlayingInfo dictionary.

Everything works fine and I even see a cover photo on the lock screen. Except the pause/play button. It always looks like pause even if my AVAudioPlayer is playing. It sends a pause event regardless of playback state.

How can I notify iOS that AVAudioPlayer is paused and that it should now show a play button in the remote control buttons bar?

like image 498
openfrog Avatar asked Sep 09 '13 19:09

openfrog


Video Answer


1 Answers

Make sure that you're setting the MPNowPlayingInfoPropertyPlaybackRate property. 0.0f to indicate paused, 1.0f to indicate playing. You'll also need to set the MPNowPlayingInfoPropertyElapsedPlaybackTime when you change these values.

Here is example code where updateMetadata is a function that applies those changes to the MPNowPlayingInfoCenter.nowPlayingInfo dictionary. This would indicate to the center that the player is paused.

[self updateMetadata:[NSDictionary dictionaryWithObjectsAndKeys:
     [NSNumber numberWithDouble:audioFile.player.currentTime], 
      MPNowPlayingInfoPropertyElapsedPlaybackTime,
     [NSNumber numberWithFloat:0.0f],  
      MPNowPlayingInfoPropertyPlaybackRate,
      nil]];
like image 101
Jan Pittner Avatar answered Sep 18 '22 02:09

Jan Pittner