视频在Android的WebView中不打 [英] Video not playing in android webview

查看:532
本文介绍了视频在Android的WebView中不打的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加载HTML页面的资源文件夹到Android的WebView,HTML页面有视频。但是视频不是在玩,我在​​这里分享code。

 <!DOCTYPE HTML>
   < HEAD>
   <标题>< /标题>
   < META HTTP-EQUIV =内容类型内容=text / html的;字符集= ISO-8859-1>
   <脚本类型=文/ JavaScript的字符集=utf-8SRC =的Video.js>< / SCRIPT>
   <脚本>
    功能连接(){
video1.play();
   }
   < / SCRIPT>
   < /头>
   <身体GT;
   < D​​IV ID =T2WIDTH =1024HEIGHT =768的风格=背景 - 图像:网址(图像/ L6_P007.jpg);背景重复:不重复;>
    <视频ID =VIDEO1WIDTH =1024HEIGHT =768的海报=图像/ L6_P007.jpg控制自动播放onended =EN(); >
    <信源SRC =视频/ L6_P007.mp4TYPE =视频/ MP4>
    <信源SRC =视频/ L6_P007.ogvTYPE =视频/ OGG>
    <信源SRC =视频/ L6_P007.webmTYPE =视频/ W​​EBM>    < /视频>
    < / DIV>
    < /身体GT;
    < / HTML>

这是我的Java code

 的WebView的WebView =(的WebView)findViewById(R.id.webView1);
webview.getSettings()setJavaScriptEnabled(真)。
webview.setWebViewClient(新WebViewClient());
。webview.getSettings()setPluginState(WebSettings.PluginState.ON_DEMAND);
    webview.loadUrl(文件:///android_asset/videosamp/videosamp.html);


解决方案

这个问题是在SO讨论过很多次。检查答案类似的问题这里
获得的VideoPlayer插件机器人在这里。

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

此命令触发一个Intent有你的设备的视频播放器显示视频。

添加插件到您的项目
使用这个插件适用于Android的PhoneGap。

要安装该插件,将WWW /视频到项目的www文件夹,包括phonegap.js后,在HTML文件中引用它。

您的项目称为SRC / COM / PhoneGap的/插件/视频中创建一个目录,并移动VideoPlayer.java进去。

在你的 RES / XML / plugins.xml 文件中添加以下行:

 <插件名称=的VideoPlayerVALUE =com.phonegap.plugins.video.VideoPlayer/>

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

/ **
    *显示意图播放视频。
    *
    * @参数的URL网址玩
    * /
  玩(URL)
示例使用:

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

注意:当从资产文件夹播放视频,该视频首先被复制与MODE_WORLD_READABLE内部存储

I am loading html page in asset folder to android webview, the html pages has video. But video not playing, Here i share the code.

   <!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>

This is my java code

    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");

解决方案

this issue is discussed many times on SO. check the answers to similar question here get the VideoPlayer Plugin for android here.

The video player allows you to display videos from your PhoneGap application.

This command fires an Intent to have your devices video player show the video.

Adding the Plugin to your project Using this plugin requires Android PhoneGap.

To install the plugin, move www/video to your project's www folder and include a reference to it in your html file after phonegap.js.

Create a directory within your project called "src/com/phonegap/plugins/video" and move VideoPlayer.java into it.

In your res/xml/plugins.xml file add the following line:

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

Using the plugin The plugin creates the object window.plugins.videoPlayer. To use, call the play() method:

/** * Display an intent to play the video. * * @param url The url to play */ play(url) Sample use:

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");

Note: When playing video from the assets folder, the video is first copied to internal storage with MODE_WORLD_READABLE.

这篇关于视频在Android的WebView中不打的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆