2010-07-08 59 views
0

有人知道當我有多個AVPlayer時,是否有可能通過AVPLayer委託處理中斷? 我曾嘗試過幾件事情,在打電話後再次啓動兩個AVPlayer,但仍然只有一個響應並開始,第二個暫停並沒有做任何事情。處理多個AVAudioPlayer的中斷

預先感謝您的任何想法

尼亞

回答

0

我的猜測是,你需要保持你的players這樣的數組,你可以通過它們查詢和暫停/開始每一個。您可以在創建您可以在audioPlayerBeginInterruption:訪問和玩家每增加一個陣列audioPlayerEndInterruption:

蘋果的文檔暗示的打擾只能處理一個player ...如果該類曾指出的players的方法輸入,而不是player然後我會說,你可能只是做了一個循環,通過他們來輪詢像下面的代碼:

AVAudioPlayer *player; 
for (player in players) { 

    [player pause]; 
    //or [player play]; 
} 

http://developer.apple.com/iphone/library/documentation/AVFoundation/Reference/AVAudioPlayerDelegateProtocolReference/Reference/Reference.html#//apple_ref/occ/intfm/AVAudioPlayerDelegate/audioPlayerBeginInterruption

0

我敢肯定,你已經解決了這一點,但只是想記錄我的答案yway。我剛剛在iPhone(4.3.2)上測試過,我的應用程序使用兩個不同的AVAudioPlayers播放兩種不同的聲音。當接到電話我得到每個球員的中斷,對於中斷的方法:

- (void)audioPlayerBeginInterruption:(AVAudioPlayer *) player; 
- (void)audioPlayerEndInterruption:(AVAudioPlayer *) player; 

所以,你可以很容易地重新啓動這兩個球員:

- (void) audioPlayerEndInterruption:(AVAudioPlayer *) player { 
    NSLog (@"Interruption ended. Resuming audio playback."); 
    [player prepareToPlay]; 
    [player play]; 
}