4

MPMusicPlayerControllerで再生するためにMPMediaItemsを使用していMPMediaItemCollectionます。MPMediaItemの再生が終了したときにイベントを発生させるにはどうすればよいですか?

4

1 に答える 1

6

MPMusicPlayerControllerPlaybackStateDidChangeNotification通知登録:

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

これらの通知を生成するように musicPlayerController に指示します。

[self.musicPlayerController beginGeneratingPlaybackNotifications];

musicPlayerControllerのプロパティをhandlePlaybackStateChanged:確認できます。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 に答える