在Android中的WebView中自动播放Youtube视频

时间:2020-02-06 06:18:15

标签: android iframe webview

我想以自动播放方式播放youtube视频,我在android中使用WebView,并且尝试使用以下代码自动播放youtube视频,但无法播放

html页面

    <body>
        <div id="setup-box">
            <div class="bg"></div>
            <div class="message">  
                <img src="platform/common/images/setup-logo.png"><br><br>
                <span>Oynatıcı kodunuzu PixageOne platformu 'Oynatıcılar' sekmesine ekleyerek ekranınızı platforma tanımlayabilir, içeriklerinizi yayınlamaya başlayabilirsiniz.</span>
                <div class="code"><span class="block">*</span><span class="block">*</span><span class="block">*</span><span class="block">*</span><span class="block">*</span><span class="block">*</span></div>
                <div class="error" >** Lütfen İnternet Bağlantınızı Kontrol Ediniz !</div>
            </div>            
        </div>
        <video autoplay loop muted src="../Common/media/pixage.mp4" id="videoElement"></video> 
</body

android类

WebView browser = ((Activity) context).findViewById(R.id.webView);
browser.getSettings().setJavaScriptEnabled(true);
browser.loadUrl( "file:///android_asset/index.html");
browser.addJavascriptInterface(new WebAppInterface(context), "MyFunction");

browser.setWebChromeClient(new WebChromeClientCustomPoster());
//((Activity) context).setContentView(browser);
WebSettings ws = browser.getSettings();
ws.setAllowFileAccess(true);
ws.setAllowFileAccessFromFileURLs(true);
ws.setMediaPlaybackRequiresUserGesture(false);
ws.setAllowUniversalAccessFromFileURLs(true);
ws.setJavaScriptCanOpenWindowsAutomatically(true);
ws.setAllowContentAccess(true);
ws.setJavaScriptEnabled(true);
ws.setDomStorageEnabled(true);

0 个答案:

没有答案