The following code should play sound and not stop playing music using iPad Music / iPod. (On iOS 5.1, the iPod app has become a music app).
Used AVAudioSessionCategoryAmbientinstead AVAudioSessionCategorySoloAmbient. But it actually stopped the music anyway. Is there something wrong with using AVAudioSessionCategoryAmbient?
NSURL *sound0URL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"0" ofType:@"aiff"]];
audioPlayer0 = [[AVAudioPlayer alloc] initWithContentsOfURL:sound0URL error:nil];
audioPlayer0.delegate = self;
[audioPlayer0 prepareToPlay];
NSError *setCategoryErr = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&setCategoryErr];
NSLog(@"%@", setCategoryErr);
audioPlayer0.currentTime = 0;
[audioPlayer0 play];
setCategoryErrprinted as (null), so there should be no errors.
source
share