3

我正在使用 webview 播放 youtube 视频。它的工作完美,除了一个白色的空白页显示几秒钟。然后我得到加载页面指示和页面加载。我怎样才能摆脱一开始的白色空白页面。我的代码如下

public static void showVideo(final Context context, WebView webReview,
        final Activity activity, String videoid, String width, String height) {


        WebSettings webSettings = webReview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webReview.getSettings().setPluginsEnabled(true);

        webReview.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                activity.setProgress(progress * 100);
            }
        });
    /*  webReview.setWebViewClient(new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            public void onReceivedError(WebView view, int errorCode,
                    String description, String failingUrl) {
                Toast.makeText(context, description, Toast.LENGTH_LONG)
                        .show();
            }
            @Override
            public void onPageStarted(WebView view, String url,
                    Bitmap favicon) {
                Log.i("onPageStarted", "url" + url);
                super.onPageStarted(view, url, favicon);
                if (progreesDialogue != null) {
                    showProgressDialog();
                }

            }

            @Override
            public void onPageFinished(WebView view, String url) {

                if (progreesDialogue != null
                        && progreesDialogue.isShowing()) {

                    progreesDialogue.dismiss();
                }
            }

        }); */

        String data = "<html>"
                + "<head>"
                + "</head>"
                + "<body style=\"margin: 0; padding: 0\">"
                + "<iframe "
                + "type=\"text/html\" "
                + "class=\"youtube-player\" "
                + "width=\""
                + width
                + "\" "
                + "height=\""
                + height
                + "\" "
                + "src=\"http://www.youtube.com/v/"
                + videoid
                + "?controls=0&showinfo=0&showsearch=0&modestbranding=1&autoplay=1&fs=0\" "
                + "frameborder=\"0\"></iframe>" + "</body>" + "</html>";



        webReview.loadData(data, "text/html", "utf-8");
        //webReview.loadUrl("http://www.youtube.com/v/"+videoid);

    } 
}

我也尝试过未注释的 webviewclient,它在下面的代码中进行了注释。

请帮助解决这个问题。

4

1 回答 1

2
android:hardwareAccelerated='true'

在你的 AndroidManifest.xml 中使用它

于 2018-02-22T13:37:13.957 回答