9

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.
4
  • Well many applications such as MotionX-GPS will allow iPod to play background music until the voiceover occurs then it halts the music, plays the "turn left" sound, and resumes the ipod playback. I want to know how to resume the previous system audio playback once my sound has completed playing.
    – wasabi
    Jul 5, 2011 at 21:07
  • I am also facing this issue. Could you please suggest any sample code here? Thanks in advance.
    – Gopinath
    Sep 18, 2012 at 11:29
  • Could you please help me to solve this? I spent two days on this? Waiting for your reply. Please see my question for your reference : stackoverflow.com/questions/12475034/…
    – Gopinath
    Sep 19, 2012 at 9:50
  • Really i am trying to do what you have done. Could you please respond my request? Please help me. Thanks.
    – Gopinath
    Sep 20, 2012 at 5:57

1 Answer 1

7

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.

6
  • Am also struggling in the same problem. Am using AVAudioPlayer to play my app audio and used AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setActive:NO error:nil]; [audoPlayerObj Play]; [audioSession setActive:YES error:nil];. Still the other app audio not resuming after the audio palyed form my app.
    – Gopinath
    Sep 19, 2012 at 9:32
  • Could you please help me to solve this? I spent two days on this? Waiting for your reply. Please see my question for your reference : stackoverflow.com/questions/12475034/…
    – Gopinath
    Sep 19, 2012 at 9:50
  • Sorry, I'm not a frequent visitor. I tend to stay away for days. Let me look into this and get back to you.
    – rage
    Sep 24, 2012 at 12:51
  • Are you not doing this in the wrong order? You should be setting the active state to 'YES' before you start playback and 'NO' once you are done playing.
    – rage
    Sep 24, 2012 at 12:54
  • Thank you so much for your reply. I was in leave due to fever that's why i didn't reply your message. I have tried your code still the bg other app's audio not resuming. I have edited my question stackoverflow.com/questions/12475034/…. Please help me to solve this issue. Thank you and looking forward your reply.
    – Gopinath
    Sep 25, 2012 at 5:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.