MPMusicPlayerController停止发送通知

jas*_*son 1 iphone objective-c iphone-sdk-3.0

我有一个MPMusicPlayerController播放整个iPod库,当轨道改变等我订阅了通知.这一切都正常工作

当到达播放列表的末尾时,MPMusicPlayerController发送状态更改通知并停止.当我重新启动播放器时,音乐开始再次播放,但是当曲目改变时,MPMusicPlayerController不再发送通知等.

思考?

ben*_*ado 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
}
Run Code Online (Sandbox Code Playgroud)