使用 android 4 浏览器自动启动 html5 视频 [英] Autostart html5 video using android 4 browser

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

问题描述

我想使用 android 4 冰淇淋三明治浏览器自动启动 android html5 视频.我尝试了许多 java 脚本函数和 html5 视频的自动缓冲自动播放标签.但没有任何效果.我通过 android 应用程序在 webview 中启动 android chrome 客户端,该客户端应该能够自动启动视频.当点击播放按钮视频播放但不自动播放.

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.

我用谷歌搜索过 &在 Android 4 上没有发现此问题的积极结果.

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

推荐答案

Android 4+ 似乎将 play() 方法的要求更改为需要用户交互.如果您从用户事件处理程序(例如 touchstartmousedown)中触发 play(),那么您可以播放视频,只要你在同一个事件循环中运行它.

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.

这意味着你不应该使用异步触发器来调用 play(),而是在没有 setTimeout() 等的情况下在同一个事件处理程序中调用 play,所以诸如延时播放之类的东西是不可能的.

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 中相同的技巧——使用第一个用户交互事件来play()pause() 视频.这将使视频能够在以后进行操作,因为您是在用户启动的操作期间播放的.成功准备好视频后,您可以随时调用播放方法,无论调用是否在事件处理程序循环内进行.

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.

以下示例代码适用于 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();

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

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