4

我正在使用MPMusicPlayerController来玩MPMediaItems. MPMediaItemCollections 播放完毕后如何触发事件MPMediaItem

4

1 回答 1

6

注册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
    }
}
于 2010-10-26T18:59:34.277 回答