【问题标题】:android application : playing youtube video embed on webviewandroid 应用程序:播放嵌入在 webview 上的 youtube 视频
【发布时间】:2013-04-08 23:06:50
【问题描述】:

我阅读了几个关于我的问题的任务,但我不知道该怎么做。 我有嵌入 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");

【问题讨论】:

    标签: android webview youtube embed playing


    【解决方案1】:

    将此添加到您的清单中

    <application android:hardwareAccelerated="true" ... />
    

    【讨论】:

    • 然后?问题是什么 ?我认为您使用 Android 4.0+ 上的设备测试您的应用程序,并且在此,您需要使用硬件加速启用。在您的清单中,设置“”并将您的构建项目设置为 android api 16
    • 因为我有这个当我构建m项目时:Android资源错误:在包'android'中找不到属性'hardwareAccelerated'的资源标识符
    • 将您的构建项目设置为 17。如果在清单中将 minSdk 设置为 4,您的应用程序仍将与 api 4 兼容
    • 好的,我今天测试一下。我觉得在法语之间说英语有点不幸,但这是游戏:)。感谢帮助!
    • 我也是 :) 如果您需要更多帮助,请在 Twitter 上找到我@pauland51
    猜你喜欢
    • 1970-01-01
    • 2017-12-23
    • 2012-10-12
    • 2012-12-14
    • 2013-11-19
    • 1970-01-01
    • 2015-03-18
    • 1970-01-01
    • 2013-07-13
    相关资源
    最近更新 更多