我使用以下代码来了解 currentplayback 时间。但是当我使用MPMusicPlayerController
播放歌曲时它无法正常工作。请帮助我。任何想法或建议都可能非常感激
[self addObserver:self forKeyPath:@"musicPlayer.currentPlaybackTime" options:0 context:nil];
歌曲播放代码
MPMediaItemCollection *collection = [[MPMediaItemCollection alloc] initWithItems:[NSArray arrayWithObject:song]];
[musicPlayer setQueueWithItemCollection:collection];
[musicPlayer prepareToPlay];
[musicPlayer setNowPlayingItem:song];
//[self.musicPlayer setVolume:volumeSlider.value];
[musicPlayer play];
答案 0 :(得分:2)
如Volker所述,该财产不符合KVO标准。请参阅此处的文档以了解要监听的nsnotification事件。还要确保你打电话
[musicplayer beginGeneratingPlaybackNotifications]
和
[musicplayer endGeneratingPlaybackNotifications]
作为参考,这些是mpmusicplayercontroller发布的通知:
MPMusicPlayerControllerPlaybackStateDidChangeNotification
MPMusicPlayerControllerNowPlayingItemDidChangeNotification
MPMusicPlayerControllerPlaybackStateDidChangeNotification
MPMusicPlayerControllerNowPlayingItemDidChangeNotification