Can you autoplay HTML5 videos on the iPad?(你能在 iPad 上自动播放 HTML5 视频吗?)
问题描述
<video>
标签 autoplay="autoplay"
属性在 Safari 中运行良好.
The <video>
tags autoplay="autoplay"
attribute works fine in Safari.
在 iPad 上测试时,必须手动激活视频.
When testing on an iPad, the video must be activated manually.
我认为这是加载问题,所以我运行了一个循环检查媒体的状态:
I thought it was a loading issue, so I ran a loop checking for the status of the media:
videoPlay: function(){
var me = this;
console.log('STATE: ' + $("#periscopevideo").get(0).readyState);
if ($("#periscopevideo").get(0).readyState != 4){
setTimeout(function(){me.videoPlay();}, 300);
}
else {
$("#periscopevideo").get(0).play();
}
}
状态在 iPad 上保持在 0
.在我的桌面 safari 中,它经过 0
、1
,最后是 4
.在 iPad 上,如果我手动点击播放"箭头,它只会达到 4
.
The state remains at 0
on the iPad. On my desktop safari, it goes through 0
, 1
and finally 4
.
On the iPad, it only reaches 4
if I manually tap the "play" arrow.
此外,通过 onClick
从点击中调用 $("#periscopevideo").get(0).play()
也可以.
Moreover, calling $("#periscopevideo").get(0).play()
from an click via onClick
works too.
Apple 对自动播放有任何限制吗?(顺便说一下,我正在运行 iOS 5+).
Is there any restrictions by Apple in regard to autoplay? (I'm running iOS 5+ by the way).
推荐答案
iOS 10 更新
自 iOS 10 起,自动播放的禁令已解除 - 但有一些限制(例如,如果没有音轨,则 A 可以自动播放).
The ban on autoplay has been lifted as of iOS 10 - but with some restrictions (e.g. A can be autoplayed if there is no audio track).
要查看这些限制的完整列表,请参阅官方文档:https://webkit.org/blog/6784/new-video-policies-for-ios/
To see a full list of these restrictions, see the official docs: https://webkit.org/blog/6784/new-video-policies-for-ios/
iOS 9 及之前的版本
从 iOS 6.1 开始,无法再在 iPad 上自动播放视频.
As of iOS 6.1, it is no longer possible to auto-play videos on the iPad.
我对他们为什么禁用自动播放功能的假设?
My assumption as to why they've disabled the auto-play feature?
嗯,由于许多设备所有者在他们的设备上都有数据使用/带宽限制,我认为 Apple 认为用户应该自己决定何时开始使用带宽.
Well, as many device owners have data usage/bandwidth limits on their devices, I think Apple felt that the user themselves should decide when they initiate bandwidth usage.
经过一番研究,我在 Apple 文档中发现了以下关于 iOS 设备自动播放的摘录,以证实我的假设:
After a bit of research I found the following extract in the Apple documentation in regard to auto-play on iOS devices to confirm my assumption:
Apple 已决定禁用自动播放视频在 iOS 设备上,通过脚本和属性实现.
"Apple has made the decision to disable the automatic playing of video on iOS devices, through both script and attribute implementations.
在 Safari 中,在 iOS 上(适用于所有设备,包括 iPad),用户可能在蜂窝网络上并按数据单位、预加载和自动播放被禁用.在用户启动之前不会加载数据." - Apple 文档.
In Safari, on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and auto-play are disabled. No data is loaded until the user initiates it." - Apple documentation.
这是 Safari HTML5 参考页面关于为什么嵌入式媒体无法在 iOS 上的 Safari 中播放:
Here is a separate warning featured on the Safari HTML5 Reference page about why embedded media cannot be played in Safari on iOS:
警告:为了防止在移动网络上未经请求的下载用户的费用,嵌入式媒体不能自动播放iOS 上的 Safari——用户总是启动播放.控制器是在 iPhone 或 iPod touch 上播放后自动提供已启动,但对于 iPad,您必须设置控件属性或使用 JavaScript 提供控制器.
Warning: To prevent unsolicited downloads over cellular networks at the user’s expense, embedded media cannot be played automatically in Safari on iOS—the user always initiates playback. A controller is automatically supplied on iPhone or iPod touch once playback in initiated, but for iPad you must either set the controls attribute or provide a controller using JavaScript.
<小时>
这意味着(就代码而言)Javascript 的 play()
和 load()
方法在用户开始播放之前是不活动的,除非 play()
或 load()
方法由用户操作(例如点击事件)触发.
What this means (in terms of code) is that Javascript's play()
and load()
methods are inactive until the user initiates playback, unless the play()
or load()
method is triggered by user action (e.g. a click event).
基本上,用户启动的播放按钮可以工作,但是onLoad="play()"
事件不会.
Basically, a user-initiated play button works, but
an onLoad="play()"
event does not.
例如,这将播放电影:
<input type="button" value="Play" onclick="document.myMovie.play()">
而以下内容在 iOS 上不会执行任何操作:
Whereas the following would do nothing on iOS:
<body onload="document.myMovie.play()">
这篇关于你能在 iPad 上自动播放 HTML5 视频吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:你能在 iPad 上自动播放 HTML5 视频吗?
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01