Audio in html of ios webview control doesnot work

2019-08-06 17:08发布

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条回答
SAY GOODBYE
2楼-- · 2019-08-06 17:17

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.

查看更多
登录 后发表回答