ara*_*ide 3 iphone events mpmediaitem mpmusicplayercontroller
我使用的是MPMusicPlayerController打MPMediaItems的MPMediaItemCollection.如何在MPMediaItems完成比赛时发射一个事件?
谢谢!InterDev中
注册MPMusicPlayerControllerPlaybackStateDidChangeNotification通知:
[notificationCenter addObserver:self selector:@selector(handlePlaybackStateChanged:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:self.musicPlayer];
Run Code Online (Sandbox Code Playgroud)
并告诉你的musicPlayerController生成这些通知:
[self.musicPlayerController beginGeneratingPlaybackNotifications];
Run Code Online (Sandbox Code Playgroud)
在handlePlaybackStateChanged:你可以检查playbackStatemusicPlayerController 的属性:
- (void)handlePlaybackStateChanged:(NSNotitication*)notification
{
if (self.musicPlayerController.playbackState == MPMusicPlaybackStateStopped ||
self.musicPlayerController.playbackState == MPMusicPlaybackStateInterrupted ||
self.musicPlayerController.playbackState == MPMusicPlaybackStatePaused) {
// do your stuff
}
}
Run Code Online (Sandbox Code Playgroud)