Reputation: 1362
When using notification center, how do you determine that the song has ended?
NSNotificationCenter.defaultCenter().addObserver(self,
selector:#selector(updateNowPlayingInfo),
name: MPMusicPlayerControllerPlaybackStateDidChangeNotification,
object: musicPlayer)
Upvotes: 0
Views: 180
Reputation: 36
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.
Upvotes: 1
Reputation: 4657
In the updateNowPlayingInfo
method check the playbackState
property of the MPMusicPlayerController
. If the song has ended the value will be Stopped
. Notice that you will also have this state if the playback was stopped manually, for instance by pressing a stop button, so you will have to check for that.
Upvotes: 1