2009-08-24 89 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 
}