android:webview播放youtube视频显示白色空白页几秒钟

时间:2013-02-14 09:45:06

标签: android video webview

我正在使用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取消注释,在下面的代码中有注释。

请帮忙解决这个问题。

1 个答案:

答案 0 :(得分:0)

android:hardwareAccelerated='true'

在AndroidManifest.xml中使用它