Search code examples
iosaudioalarm

how to play a sound alarm or soundeffect that doesn't stop itunes or other music players?


I'm working on a sport timer app, that should play alarms after a couple of seconds. Everything works so far but It stops all music players. I used the AVAudioPlayer Class to play the sound. Is there any other way to play the alarms?

thx Dan


Solution

  • You need to look into audio session categories. The default category AVAudioSessionCategorySoloAmbient disables other audio, but AVAudioSessionCategoryAmbient should leave the other audio playing. If using AVAudioSession, you could try this:

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

    You should still be able to use AVAudioPlayer.