开发者

Handling interruption for multiple AVAudioPlayers

Is it possible to handle interruption by AVPLayer delegate when I have more then one AVPlayer? I have tried few things to start again two AVPlayer after phone call, but still only one respon开发者_C百科d and started, the second one was paused and did nothing.


My guess is that you need to keep an array of your players so that you can poll through them and pause/start each one. You can add each to an array when you create the player which you can access in audioPlayerBeginInterruption: and audioPlayerEndInterruption:

Apple's docs imply that the interruptions only handle one player ...if the class had stated a method input of players instead of player then I would have said you could have just done a for loop to poll through them like the code below:

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:


I'm sure you've solved this already, but just wanted to log my answer anyway. I've just tested this on an IPhone (4.3.2), my application is playing two different sounds with two different AVAudioPlayers. When receiving a phone call I DO get an interruption for each player, for both interruption methods:

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

So you can easily re-start both players:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜