iOS: Playing audio in silent mode [duplicate]

倖福魔咒の 提交于 2019-12-23 03:53:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!