iOS:以静音模式播放音频 [英] iOS: Playing audio in silent mode
本文介绍了iOS:以静音模式播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
即使用户的静音/静音开关设置为静音/振动,让我的应用播放音频的正确"方法是什么?
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?
一些背景: 我实际上是在调试阶段运行它的,但是当我将应用程序提交给Apple并随后从应用程序商店下载它时,音频在静音模式下被禁用了!这是我如何使其在调试阶段工作的方法:
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];
推荐答案
我认为它具有相同的作用,但是您是否尝试过像这样通过AVFoundation设置设置?
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];
这篇关于iOS:以静音模式播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文