【问题标题】:Unable show youtube embed video in Webview without "http/https"无法在没有“http/https”的情况下在 Webview 中显示 youtube 嵌入视频
【发布时间】:2016-08-21 13:36:29
【问题描述】:

目前我正在开发新闻阅读器 android 应用程序,并在 webview 中显示文章,在显示来自 youtube 的嵌入式视频时遇到一些问题,我的所见即所得生成代码如下

<iframe height="360" width="640" src="//www.youtube.com/embed/PS6JupCFnNM" frameborder="0" allowfullscreen></iframe>

但它无法在 webview 中加载,然后我找到了解决此问题的方法,例如在 src url 中添加 http/https

<iframe width="560" height="315" src="https://www.youtube.com/embed/PS6JupCFnNM" frameborder="0" allowfullscreen></iframe>

第二种格式是我从那里复制的youtube嵌入框的原始格式,它可以工作,现在我应该做什么,有没有办法让webview以src="//www.youtube.com/embed/PS6JupCFnNM"格式显示youtube视频,或者我必须修改我的所见即所得? 谢谢你的帮助。我希望我的问题不会与另一个 webview 问题重复。

【问题讨论】:

  • 如何将 HTML 加载到 WebView 中?
  • 我刚刚放入webview.loadData(htmlCode, "text/html", "utf-8");,目前我在我的API中使用str_replace在iframe标签的src中添加httpshttp

标签: android webview youtube


【解决方案1】:

切换到 loadDataWithBaseURL(),您提供的基本 URL 具有 https 方案。

【讨论】:

    【解决方案2】:

    您必须使用基本网址。

    webView.loadDataWithBaseURL("http://.", htmlCode, TEXT_HTML, "UTF-8", "");
    

    【讨论】:

      【解决方案3】:

      我是通过添加utf-8 编码完成的。 像这样:

      webview.loadData(html,"text/html", "utf-8");
      

      【讨论】:

        猜你喜欢
        • 2017-07-22
        • 2014-04-11
        • 2015-02-08
        • 2015-05-06
        • 1970-01-01
        • 1970-01-01
        • 2011-07-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多