2009-08-24 91 views
1

我有一个MPMusicPlayerController玩整个的iPod库,我当轨道改变订阅通知等,这是所有工作正常MPMusicPlayerController停止发送通知

当到达播放列表的末尾,MPMusicPlayerController发送状态通知的更改和停止。当我重新启动播放器时,音乐开始再次播放,但MPMusicPlayerController不再在音轨更改时发送通知等。

想法?

回答

3

经过大量的实验后,这是什么解决了我的问题。

事实证明,通知正在发送,状态被报告为“已停止”;然而,发送“播放”消息仅导致另一个通知发射并且状态仍然显示为“停止”。

虽然玩家在到达队列末尾时停止播放,但并未“完全”停止播放,我最好的猜测是当它停止播放时,它没有正确重置队列状态或类似的东西,因为我发现,如果我在收到停止通知后发送了“停止”消息,我就可以发送“播放”消息并让播放器正常启动。

8

显然,MPMusicPlayerControllerPlaybackStateDidChangeNotification有时会在播放器对象实际更新其状态之前发布。但是,您仍然可以从通知的userInfo字典中获取新状态(可能正是出于此原因)。

在代码:

- (void)playbackStateDidChange:(NSNotification *)notification { 
    static NSString * const stateKey = @"MPMusicPlayerControllerPlaybackStateKey"; 
    NSNumber *number = [[notification userInfo] objectForKey:stateKey]; 
    MPMusicPlaybackState state = [number integerValue]; 
    // state is the new state 
    MPMusicPlayerController *player = [notification object]; 
    // state may not be equal to player.playbackState 
}