Audio in html of ios webview control doesnot work

◇◆丶佛笑我妖孽 提交于 2019-12-24 13:23:00

问题


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?


回答1:


Please add below code:-

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

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.



来源:https://stackoverflow.com/questions/28600878/audio-in-html-of-ios-webview-control-doesnot-work

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