Using MPMusicPlayerController plays MPMediaItemCollection how to get event at the end of playback

I use MPMusicPlayerControllerto play MPMediaItemsin MPMediaItemCollection. How can I fire an event on execution MPMediaItem?

Thank! Interdev

+3
source share
1 answer

Register for notifications MPMusicPlayerControllerPlaybackStateDidChangeNotification:

[notificationCenter addObserver:self selector:@selector(handlePlaybackStateChanged:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:self.musicPlayer];

and tell the musicPlayerController file these notifications:

[self.musicPlayerController beginGeneratingPlaybackNotifications];

In handlePlaybackStateChanged:you can check the property playbackStatefor musicPlayerController:

- (void)handlePlaybackStateChanged:(NSNotitication*)notification
{
    if (self.musicPlayerController.playbackState == MPMusicPlaybackStateStopped ||
        self.musicPlayerController.playbackState == MPMusicPlaybackStateInterrupted ||
        self.musicPlayerController.playbackState == MPMusicPlaybackStatePaused) {
        // do your stuff
    }
}
+5
source

Source: https://habr.com/ru/post/1771504/


All Articles