【问题标题】:Video not playing in android webview视频无法在 android webview 中播放
【发布时间】:2013-02-08 10:20:01
【问题描述】:

我正在将资产文件夹中的 html 页面加载到 android webview,html 页面有视频。但是视频没有播放,这里我分享代码。

   <!doctype html>
   <head>
   <title></title>
   <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
   <script type="text/javascript" charset="utf-8" src="video.js"></script> 
   <script>
    function en(){
video1.play();
   }
   </script>
   </head>
   <body>
   <div id="t2" width ="1024" height="768" style="background-     image:url(images/L6_P007.jpg); background-repeat:no-repeat;">
    <video id="video1" width="1024" height="768" poster="images/L6_P007.jpg" controls  autoplay onended="en();" >
    <source src="videos/L6_P007.mp4" type="video/mp4">
    <source src="videos/L6_P007.ogv" type="video/ogg">
    <source src="videos/L6_P007.webm" type="video/webm">

    </video>
    </div>
    </body>
    </html>

这是我的java代码

    WebView webview = (WebView) findViewById(R.id.webView1);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
    webview.loadUrl("file:///android_asset/videosamp/videosamp.html");

【问题讨论】:

标签: android android-webview


【解决方案1】:

这个问题在 SO 上讨论过很多次。检查类似问题的答案here 获取 VideoPlayer Plugin for android here.

视频播放器允许您显示来自 PhoneGap 应用程序的视频。

此命令会触发 Intent,让您的设备视频播放器显示视频。

将插件添加到您的项目中 使用此插件需要 Android PhoneGap。

要安装插件,请将 www/video 移动到项目的 www 文件夹,并在 phonegap.js 之后的 html 文件中包含对它的引用。

在您的项目中创建一个名为“src/com/phonegap/plugins/video”的目录并将 VideoPlayer.java 移入其中。

在您的 res/xml/plugins.xml 文件中添加以下行:

<plugin name="VideoPlayer" value="com.phonegap.plugins.video.VideoPlayer"/>

使用插件 该插件创建对象 window.plugins.videoPlayer。要使用,请调用 play() 方法:

/** *显示播放视频的意图。 * * @param url 要播放的 url */ 播放(网址) 样品使用:

window.plugins.videoPlayer.play("http://path.to.my/video.mp4");
window.plugins.videoPlayer.play("file:///path/to/my/video.mp4");
window.plugins.videoPlayer.play("file:///android_asset/www/path/to/my/video.mp4");
window.plugins.videoPlayer.play("https://www.youtube.com/watch?v=en_sVVjWFKk");

注意:播放资产文件夹中的视频时,首先将视频复制到带有 MODE_WORLD_READABLE 的内部存储中。

【讨论】:

  • 我编辑了我的问题,你能分享如何使用插件在android webview中加载html页面
  • 完成,如果我的回答有帮助,请不要忘记支持/接受它
  • 我必须在 android webview 中加载 html 页面,而不是在 vidoe 视图中
  • 请检查我提供的链接,android webview 不支持来自 html5 的视频标签,这就是我们需要使用这个库的原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-18
  • 1970-01-01
  • 2011-11-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多