While working on a iPhone project recently, I was looking for a way of playing sound effects via AVAudioPlayer at the same time as music playback via iPodMusicPlayer and had been running into problems until I found this blog post from Sputnik Games (thanks guys!) which solved my problem. Add the following code to the application-didFinishLaunchingWithOptions method in your app delegate in order to solve the problem:
OSStatus result = AudioSessionInitialize(NULL, NULL, NULL, self);
if (result) {
// Init error, handle error here
} else {
UInt32 category = kAudioSessionCategory_AmbientSound;
result = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
sizeof(category), &category);
if (result) {
// set audio session error, handle error here
} else {
result = AudioSessionSetActive(true);
if (result) {
// Set audio session active error, handle error here
}
}
}