ios 网络视图控件的 html 中的音频不工作
Audio in html of ios webview control doesnot work
我在 html 中包含了一个音频标签,我正在 UIWebview 控件中加载 html。当我点击播放按钮时播放音频。但是,当我将 phone 置于静音模式时,它会停止播放并转为静音。
即使 phone 处于静音模式,我也希望播放音频。
谁能帮我解决这个问题?
请添加以下代码:-
NSError *setCategoryErr = nil;
NSError *activationErr = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];
如果您想要 运行 音频,即使应用程序处于后台模式,也可以在 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];
希望,现在这对你有所帮助。
我在 html 中包含了一个音频标签,我正在 UIWebview 控件中加载 html。当我点击播放按钮时播放音频。但是,当我将 phone 置于静音模式时,它会停止播放并转为静音。
即使 phone 处于静音模式,我也希望播放音频。
谁能帮我解决这个问题?
请添加以下代码:-
NSError *setCategoryErr = nil;
NSError *activationErr = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];
如果您想要 运行 音频,即使应用程序处于后台模式,也可以在 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];
希望,现在这对你有所帮助。