我在html中包含一个音频标签,并且正在UIWebview控件中加载html。当我单击“播放”按钮时,将播放音频。但是,当我将手机置于静音模式时,它将停止播放,而是进入静音状态。
我希望即使手机处于静音模式也能播放音频。
谁能帮我这个忙吗?
最佳答案
请添加以下代码:-
NSError *setCategoryErr = nil;
NSError *activationErr = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];
如果您要运行音频,即使应用程序处于后台模式,也要在应用程序中使用以下代码:didFinishLaunchingWithOpitons :
[[AVAudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
applicationDidEnterBackground:
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
希望,现在对您有帮助。
关于html - iOS WebView控件的HTML中的音频不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28600878/