iOS WKWebView播放音視頻沒(méi)有聲音

在初始化?WKWebViewConfiguration 的時(shí)候 添加下面的代碼! 我這邊是解決了!


WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];

? ? if(@available(iOS10.0, *)) {

? ? ? ? config.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;

? ? }else{

? ? ? ? // Fallback on earlier versions

? ? }


? ? config.allowsInlineMediaPlayback = YES;

? ? // 自動(dòng)播放, 不需要用戶采取任何手勢(shì)開(kāi)啟播放

? ? // WKAudiovisualMediaTypeNone 音視頻的播放不需要用戶手勢(shì)觸發(fā), 即為自動(dòng)播放

? ? config.allowsAirPlayForMediaPlayback = YES;

? ? config.allowsPictureInPictureMediaPlayback = YES;


? ? //? ? ? ? 自定義的WKScriptMessageHandler 是為了解決內(nèi)存不釋放的問(wèn)題

? ? MWebViewScriptMessageDelegate *weakScriptMessageDelegate = [[MWebViewScriptMessageDelegate alloc] initWithDelegate:self];

? ? //這個(gè)類主要用來(lái)做native與JavaScript的交互管理

? ? WKUserContentController * wkUController = [[WKUserContentController alloc] init];

? ? //? ? ? ? 注冊(cè)一個(gè)name為jsToOcNoPrams的js方法 設(shè)置處理接收J(rèn)S方法的對(duì)象


? ? 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.

? ? }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容