问题
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