I have music playing within my application using a MPMusicPlayerController
, using iPodMusicPlayer
(also tried applicationMusicPlayer). When I play a sound using AVAudioPlayer
my music from my MPMusicPlayerController
will stop. Is there a way to have the MPMusicPlayerController
and the AVAudioPlayer
play sounds simultaneously?
Asked
Active
Viewed 2,825 times
7
-
Any chance you can mark my answer as correct, like in a 5 year delay? :) – Oded Ben Dov Jan 25 '16 at 21:12
2 Answers
13
Hey, found the solution on the web.
Write these 2 lines somewhere, I did it in application:didFinishLaunchingWithOptions
// Set sounds not to stop music
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
Must admit I didn't delve into the details, but it works...
Good luck!
Oded.

Oded Ben Dov
- 9,936
- 6
- 38
- 53
4
Oded Ben Dov's solution does the job, but you might not want to change your session category. For example, if you want your audio to keep playing while the screen is locked, you need the Playback category.
In that case, you can apply this category override instead:
UInt32 mixWithOthers = YES;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(mixWithOthers), &mixWithOthers);

arlomedia
- 8,534
- 5
- 60
- 108