我正在使用MPMusicPlayerController
在MPMediaItems
中播放MPMediaItemCollection
。如何在MPMediaItem
完成播放时触发事件?
谢谢! InterDev中
答案 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
}
}