Search code examples
iosmpmediaplayercontroller

MPMusicPlayerControllerPlaybackStateDidChangeNotification determine if song has ended


When using notification center, how do you determine that the song has ended?

NSNotificationCenter.defaultCenter().addObserver(self,
                                                     selector:#selector(updateNowPlayingInfo),
                                                     name: MPMusicPlayerControllerPlaybackStateDidChangeNotification,
                                                     object: musicPlayer)

Solution

  • The nowPlayingItem should change when song has finished playing. In conjunction with the playback state, that should be enough to determine if the song has finished playing to the end.