ios webview控件的html中的音频不起作用 [英] Audio in html of ios webview control doesnot work

查看:28
本文介绍了ios webview控件的html中的音频不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 html 中包含了一个音频标签,我正在 UIWebview 控件中加载 html.当我单击播放按钮时播放音频.但是当我将手机置于静音模式时,它会停止播放,而是静音.

I have included a audio tag in html and i am loading the html inside the UIWebview control. The audio plays when i click on the play button. But when i put the phone in silent mode it stops playing and instead goes on mute.

我希望即使手机处于静音模式也能播放音频.

I want the audio to play even when the phone is in silent mode.

有人可以帮我解决这个问题吗?

Can anyone please help me with this?

推荐答案

请添加以下代码:-

NSError *setCategoryErr = nil;
NSError *activationErr  = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];

如果即使应用程序处于后台模式也想运行音频,请在 application:didFinishLaunchingWithOpitons 中使用以下代码:

IF you want to run audio even if app is in background mode than use below code in application: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];

希望,现在这会对你有所帮助.

Hope, now this will help you.

这篇关于ios webview控件的html中的音频不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆