问题
What is the "correct" way to get my app to play audio even if the user's silent/mute switch is set to silent/vibrate?
Some background: I actually got it working in debug stage, but when I submitted my app to Apple and then later downloaded it from the app store, the audio was disabled in silent mode! Here is how I got it working in debug stage:
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory), &sessionCategory);
Audio was played using:
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp3"];
AVAudioPlayer *theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
回答1:
I think it does the same thing, but have you tried, setting the setting throught AVFoundation like so?
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
来源:https://stackoverflow.com/questions/9913712/ios-playing-audio-in-silent-mode