android应用程序:播放youtube视频嵌入webview

时间:2013-04-16 13:46:58

标签: android webview youtube embed playing

我读了几个关于我的问题的任务,但我不知道该怎么办。 我有youtube视频嵌入的webview。 当我点击时,我有声音而不是视频。 我补充一点:

content.setWebChromeClient(new WebChromeClient() {});

但它不起作用!

这是我的网页浏览:

    content = new WebView(this);
    content.setLayoutParams(new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT,
            Gravity.CENTER
    ));
    content.setHorizontalScrollBarEnabled(false);
    content.setVerticalScrollBarEnabled(false);
    content.getSettings().setJavaScriptEnabled(true);
    content.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    content.getSettings().setBuiltInZoomControls(false);
    content.getSettings().setSupportZoom(true);
    content.getSettings().setUseWideViewPort(true);
    content.getSettings().setPluginsEnabled(true);
    content.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    content.getSettings().setSavePassword(true);
    content.getSettings().setSaveFormData(true);
    content.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

    content.setWebChromeClient(new WebChromeClient() {

    });
    content.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            close();
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            view.setVisibility(View.VISIBLE);
            showLayout();
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Uri overrideUrl = null;
            Uri currentUrl = Uri.parse(url);
            if (data.getFormat().equals(Format.IMAGE)) {
            ...
            }
            if (overrideUrl != null) {
                Intent browser = new Intent(Intent.ACTION_VIEW);
                browser.setData(overrideUrl);
                startActivity(browser);
                return false;
            }
            view.loadUrl(url);
            return true;
        }
    });

    layout.addView(content);
    content.loadData(data.getHtml(), "text/html", "UTF-8");

1 个答案:

答案 0 :(得分:0)

在清单

中添加此内容
<application android:hardwareAccelerated="true" ... />