1

I need to play a custom sound synthesized using AudioUnit on an iPod. This sound shall be played after up to one hour of playing music from a playlist on the iPod (it is played using MPMusicPlayerController). The issue is that everything works fine if the screen in on, however my custom sound doesn't play if the screen is off.
If the sound is already playing when the screen is turned off it keeps playing well. So I assume I am using the correct audio session category.

Could you give me any hint?

OtoLeo
  • 363
  • 3
  • 19

1 Answers1

0

According to Apple's developer library:

AVAudioSessionCategoryPlayback or the equivalent kAudioSessionCategory_MediaPlayback—Use this category for an application whose audio playback is of primary importance. Your audio plays even with the screen locked and with the Ring/Silent switch set to silent.

(Also, check this table.)

It seems that setting the audio session category to AVAudioSessionCategoryPlayback or kAudioSessionCategory_MediaPlayback would automatically fix your problem.

rahzark
  • 494
  • 1
  • 4
  • 13
  • thanks for your answer, but I was already using AVAudioSessionCategoryPlaback and it is still not working. Music is played correctly but when my synthesized sound should play, nothing happens. It will play only once I unlock the screen. It's weird. – OtoLeo Jan 11 '12 at 15:15
  • Wierd indeed. I wish I could be more helpful. Still, I would check all the basics: make sure the session is not only initialized but set as active as well. – rahzark Jan 11 '12 at 16:28
  • I finally got it working. I had to set kAudioSessionProperty_OverrideCategoryMixWithOthers. At the beginning I thought it was not required because I don't need both music and sound at the same time. – OtoLeo Jan 11 '12 at 19:20
  • Yeah, seems strange to require kAudioSessionProperty_OverrideCategoryMixWithOthers for that. Just another strange behavior for AudioSession... – rahzark Jan 12 '12 at 18:26