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

was*_*abi 7 audio avaudioplayer ios

在我的应用程序使用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.
Run Code Online (Sandbox Code Playgroud)

rag*_*age 7

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