【问题标题】:Auto Play Youtube in Android Webview在 Android Webview 中自动播放 Youtube
【发布时间】:2019-02-23 16:02:42
【问题描述】:

Youtube 自动播放标签在 Android Webview iframe 中不起作用。 怎么去掉cc标签?

HTML 需要在 webview 中加载:

<!DOCTYPE html>
<html>
    <style>
    .center{
        position: absolute;
        margin: auto auto;
        right: 0;
        left: 0;
        bottom: 0;
        top: 0;
    }

    </style>
    <body style="background:#000">
        <iframe id="videoContainer" class="center" width="100%" height="300"
                src="https://www.youtube.com/embed/5jnqWIlaLyA?rel=0&controls=1&showinfo=0&autoplay=1"
                frameborder="0" allow="autoplay; encrypted-media" allowfullscreen>
        </iframe>
    </body>
</html>

在网站上运行相同的代码。

Content 变量保存上面提到的 html。 当前的 Android 代码:

 mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setAppCacheEnabled(false);
        mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        mWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);

        view.loadDataWithBaseURL(null, content, "text/html", "utf8", view.getUrl());

【问题讨论】:

    标签: java android iframe webview youtube


    【解决方案1】:

    自 Android SDK 17 起默认禁用自动播放,您可以将 setMediaPlaybackRequiresUserGesture 设置为 false 以重新启用自动播放。然后您还需要检查 SDK 版本,因为此功能不在早期版本中。

    支票:

    int SDK_INT = android.os.Build.VERSION.SDK_INT;
    if (SDK_INT > 16) {
        engine.getSettings().setMediaPlaybackRequiresUserGesture(false);
    }
    

    【讨论】:

    • 您是否在 webView 上将 setMedioPlaybackRequiresUserGesture 设置为 true?
    【解决方案2】:

    【讨论】:

    • 已经检查过了,在我看来,格式是正确的。如果我做错了,请告诉我
    • 请检查问题
    猜你喜欢
    • 1970-01-01
    • 2016-10-25
    • 2012-12-14
    • 2012-09-24
    • 1970-01-01
    • 2017-12-23
    • 2011-04-23
    • 1970-01-01
    • 2013-07-13
    相关资源
    最近更新 更多