iOS WKWebView播放音视频没有声音

源代码 2024-9-13 17:36:44 156 0 来自 中国
在初始化 WKWebViewConfiguration 的时间 添加下面的代码! 我这边是办理了!


WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
    if(@available(iOS10.0, *)) {
        config.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
    }else{
        // Fallback on earlier versions
    }


    config.allowsInlineMediaPlayback = YES;
    // 主动播放, 不须要用户接纳任何手势开启播放
    // WKAudiovisualMediaTypeNone 音视频的播放不须要用户手势触发, 即为主动播放
    config.allowsAirPlayForMediaPlayback = YES;
    config.allowsPictureInPictureMediaPlayback = YES;


    //        自界说的WKScriptMessageHandler 是为相识决内存不开释的标题
    MWebViewScriptMessageDelegate *weakScriptMessageDelegate = [[MWebViewScriptMessageDelegate alloc] initWithDelegate:self];
    //这个类紧张用来做native与JavaScript的交互管理
    WKUserContentController * wkUController = [[WKUserContentController alloc] init];
    //        注册一个name为jsToOcNoPrams的js方法 设置处理惩罚吸取JS方法的对象


    NSError*error;
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
    if(error) {
        NSLog(@"Error in setting category = %@", error);
        //handle error here.
    }
    [[AVAudioSession sharedInstance] setActive:YES error:&error];
    if(error) {
        NSLog(@"Error in activating session = %@", error);
        //handle error here.
    }
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2025-4-10 11:05, Processed in 0.103254 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表