【发布时间】:2015-04-20 11:21:26
【问题描述】:
我在 html 中包含了一个音频标签,我正在 UIWebview 控件中加载 html。当我单击播放按钮时播放音频。但是,当我将手机置于静音模式时,它会停止播放并转为静音。
我希望即使手机处于静音模式也能播放音频。
谁能帮我解决这个问题?
【问题讨论】:
标签: html ios objective-c audio uiwebview
我在 html 中包含了一个音频标签,我正在 UIWebview 控件中加载 html。当我单击播放按钮时播放音频。但是,当我将手机置于静音模式时,它会停止播放并转为静音。
我希望即使手机处于静音模式也能播放音频。
谁能帮我解决这个问题?
【问题讨论】:
标签: html ios objective-c audio uiwebview
请添加以下代码:-
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];
希望,现在这将对您有所帮助。
【讨论】: