Thank you @ Please, indicating me the relevant part of the documents . For others with this problem, the solution is to explicitly set the session category, in my case, to the surrounding sound. This code burst from apple docs :
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound; // 1 AudioSessionSetProperty ( kAudioSessionProperty_AudioCategory, // 2 sizeof (sessionCategory), // 3 &sessionCategory // 4 );
So my audio playback method now looks like this:
-(void)playAif:(NSString *)filename { // NSLog(@"play: %@", filename); SystemSoundID soundID; NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"aif"]; if (path) { // test for path, to guard against crashes UInt32 sessionCategory = kAudioSessionCategory_AmbientSound; // 1 AudioSessionSetProperty ( kAudioSessionProperty_AudioCategory, // 2 sizeof (sessionCategory), // 3 &sessionCategory // 4 ); AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path],&soundID); AudioServicesPlaySystemSound (soundID); } }
It solves my problem conveniently! The only concern I am experiencing is that setting it explicitly every time I play a sound can be excessive. Does anyone know a better and safer way to install and forget it? Otherwise, it works amazingly.
source share