使用MPMusicPlayerController播放MPMediaItemCollection,如何在播放结束时获取事件

时间:2010-10-26 13:30:09

标签: iphone events mpmusicplayercontroller mpmediaitem

我正在使用MPMusicPlayerControllerMPMediaItems中播放MPMediaItemCollection。如何在MPMediaItem完成播放时触发事件?

谢谢! InterDev中

1 个答案:

答案 0 :(得分:5)

注册MPMusicPlayerControllerPlaybackStateDidChangeNotification通知:

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

并告诉你的musicPlayerController生成这些通知:

[self.musicPlayerController beginGeneratingPlaybackNotifications];

handlePlaybackStateChanged:中,您可以查看musicPlayerController的playbackState属性:

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