Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing sounds while ipod music is on (iPad)

Tags:

ios

ipad

ipod

What is the best pattern for an application to play sounds while enabling user to use his iPad app to play music as well? Right now if the music is playing any sound played by my app will stop the music. Is there a way to disable sounds while ipod is playing?

like image 440
adrin Avatar asked Nov 12 '10 20:11

adrin


1 Answers

By default, sounds played interrupt iPod, as you have seen. In order to tell the system that you want the sounds you're playing to be mixed in with other sounds on the system, such as iPod, you need to set the category of your AVAudioSession to AVAudioSessionCategoryAmbient, like this:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];

Do this before you begin playing sounds, and you should get the desired effect. Here's the documentation:

http://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/Reference/Reference.html#//apple_ref/doc/uid/TP40008240-CH1-SW1

like image 100
Ryan Avatar answered Nov 10 '22 09:11

Ryan