使用AVAudioPlayer播放声音后恢复背景音频

时间:2011-06-23 00:16:08

标签: ios audio avaudioplayer

在我的应用程序使用AVAudioPlayer播放自己的声音后,我正在寻找一种方法来恢复其他应用程序播放的音频。现在,如果我正在听音乐并启动我的应用程序,它会暂停音乐,播放我的声音,但不会恢复背景音乐。

以下是我正在做的产生声音播放的内容:

myChime = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"chime" ofType:@"mp3"]] error:nil];
myChime.delegate = self;
[myChime play];
// Here I am looking to resume the audio that the system was playing before my application played its sound.  I have seen many applications do this such as, GPS apps that speak a voice direction and then resume the music.

1 个答案:

答案 0 :(得分:7)

您需要正确实施AVAudioSession委托方法。如果您将音频会话设置为非活动状态,则系统将知道您已完成播放声音并将恢复任何其他音频会话。请参阅Audio Session Programming Guide,尤其是setActive:error:方法。

相关问题