Youtube embed videos not working in webview. What's wrong with this code?

后端 未结 5 1491
故里飘歌
故里飘歌 2021-02-03 11:47

I am new to android. I am facing two problems right now 1. I parsed xml file and showed it in webview which contains videos and text . When i click on videos

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-03 12:46

    Follow this source, Youtube video should play

            String youtubeId = "iiLepwjBhZE";
            int width = rl.getWidth();
            int height = rl.getHeight();
    
            WebChromeClient mWebChromeClient = new WebChromeClient(){
    
                public void onProgressChanged(WebView view, int newProgress) {
                    /*
                    view.loadUrl("javascript:(function() { " +  
                            "document.querySelector('iframe').setAttribute('style', 'width: 1080px; height: 1920px'); " + 
                            "})()");
                    */
                }
            };
    
            String video= "
    ";

    //

            webView.getSettings().setPluginState(PluginState.ON);
            webView.setWebChromeClient(mWebChromeClient);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.getSettings().setAppCacheEnabled(true);
            webView.setInitialScale(1);
            webView.getSettings().setLoadWithOverviewMode(true);
            webView.getSettings().setUseWideViewPort(true);
            //mWebView.loadDataWithBaseURL(null,load,"text/html","UTF-8",null);
            webView.loadData(video,"text/html","UTF-8");
    

提交回复
热议问题