采用安卓4.0的浏览器自动启动HTML5视频 [英] Autostart html5 video using android 4 browser

查看:361
本文介绍了采用安卓4.0的浏览器自动启动HTML5视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用安卓4.0冰淇淋三明治的浏览器自动启动Android的HTML5视频。我试过很多的Java脚本函数和HTML5视频的自动缓冲自动播放标签。但毫无效果。我开始的WebView安卓铬客户机通过Android应用程序和客户端应能自动启动录像。当点击播放按钮,播放视频,但不自动播放。

I want to auto-start android html5 video using android 4 ice cream sandwich browser. I tried many java-script functions and autobuffer autoplay tags of html5 video. But nothing worked. I start android chrome client in webview via android app and that client should be able to auto-start video. When click the play button video plays but not auto play.

时它的android限制? 另外要注意的是,任何回调方法被称为chromeClient甚至当我们点击播放按钮和放大器;在播放视频和放大器;完成。

Is it restricted in android? Other thing to notice is that no call back methods are called in chromeClient even when we click the play button & video is playing & completed.

我用Google搜索和放大器;发现在这个问题上的Andr​​oid 4.0没有阳性结果。

I have googled & found no positive result on this issue on Android 4.

推荐答案

看来,Android的4+变化的要求,要求用户交互的播放()方法。如果触发播放()从用户事件处理程序中(如 touchstart 鼠标按下),那么你可以,只要你在同一事件循环中运行它播放视频。

It seems that Android 4+ changed the requirements for the play() method to require user interaction. If you trigger play() from within a user event handler (eg. touchstart or mousedown), then you can play the video as long as you run it inside the same event loop.

这意味着,你不应该使用异步触发调用播放(),而是调用相同的事件处理程序中的播放而无需的setTimeout( )和这样的,所以这样的东西时间延迟打法是出了问题。

This means that you shouldn't use async triggers to call play(), but rather call play inside the same event handler without setTimeout() and such, so stuff like time-delayed play is out of the question.

一种方法是使用同样的伎俩在Android 4的iOS中 - 使用第一用户交互事件播放()暂停( )视频。这将在以后启用的操作视频,因为你一个用户发起的行动中发挥它。当你成功灌注的视频,你可以调用播放方式在任何时间后,无论呼叫是否有人在事件处理程序循环内与否。

One way is to use the same trick on Android 4 as in iOS – use the first user interaction event to play() and pause() the video. This will enable the video for manipulation later, since you played it during a user initiated action. After you've successfully primed the video, you can call play methods at any time later, regardless of whether the call was made inside the event handler loop or not.

编辑:下面是一个示例code对HTC和三星这样的作品,而不是Galaxy Nexus的4.1(需要用户交互播放):

Here's a sample code that works on HTC and Samsung, but not Galaxy Nexus 4.1 (requires user interaction to play):

var myVideo = document.getElementById('myvideo');

myVideo.addEventListener('canplay', function() {
  myVideo.play();
});

myVideo.load();
myVideo.play();

这篇关于采用安卓4.0的浏览器自动启动HTML5视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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