开发者

Using MPMusicPlayerController play a MPMediaItemCollection, how to get the event of at end of playing

I'm using the MPMusicPlayerController to play MPMediaItems in a MPMedia开发者_如何学JAVAItemCollection. How can I fire an event when the MPMediaItems are done playing?


Register for MPMusicPlayerControllerPlaybackStateDidChangeNotification notifications:

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

and tell your musicPlayerController to generate those notifications:

[self.musicPlayerController beginGeneratingPlaybackNotifications];

In handlePlaybackStateChanged: you can check the playbackState property of musicPlayerController:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜