Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

ios - Resume Background Audio After Playing Sound With AVAudioPlayer

I am looking for a way to resume audio played by another application after my application plays its own sound with AVAudioPlayer. Right now, if I am listening to music and launch my application, it pauses the music, plays my sound, but doesn't resume the background music.

Here is what i'm doing to generate the sound playback:

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to properly implement the AVAudioSession delegate methods. If you set the audio session to inactive, then the system will know you are done playing your sound and will resume any other audio sessions. Refer to the Audio Session Programming Guide, especially the setActive:error: method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...