【问题标题】:Audio in html of ios webview control doesnot workios webview控件的html中的音频不起作用
【发布时间】:2015-04-20 11:21:26
【问题描述】:

我在 html 中包含了一个音频标签,我正在 UIWebview 控件中加载 html。当我单击播放按钮时播放音频。但是,当我将手机置于静音模式时,它会停止播放并转为静音。

我希望即使手机处于静音模式也能播放音频。

谁能帮我解决这个问题?

【问题讨论】:

    标签: html ios objective-c audio uiwebview


    【解决方案1】:

    请添加以下代码:-

    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];
    

    希望,现在这将对您有所帮助。

    【讨论】:

    • 嗨 shreyanash 我已经尝试过这样做。它也没有帮助。
    猜你喜欢
    • 2016-11-11
    • 2012-05-19
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多