您可以在iPad上自动播放HTML5视频吗? [英] Can you autoplay HTML5 videos on the iPad?

查看:374
本文介绍了您可以在iPad上自动播放HTML5视频吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< video> 标签 autoplay =autoplay属性在Safari中正常工作。



在iPad上测试时,视频必须手动激活。



我认为这是一个加载问题,一个循环检查媒体的状态:

  videoPlay:function(){
var me = this;
console.log('STATE:'+ $(#periscopevideo)。get(0).readyState);
if($(#periscopevideo)。get(0).readyState!= 4){
setTimeout(function(){me.videoPlay();}
}
else {
$(#periscopevideo)。get(0).play();
}
}

状态保持在 0 。在我的桌面safari上,它通过 0 1 ,最后 4
在iPad上,如果我手动点击播放箭头,它只会到达 4



此外,通过 onClick 调用 $(#periscopevideo)。get(0).play()



苹果对自动播放有任何限制吗? (我正在运行iOS 5+。)

解决方案

iOS 10更新 p>

自动播放的禁令已在iOS 10中取消 - 但有一些限制(例如,如果没有音频轨道,A可以自动播放)。



要查看这些限制的完整列表,请参阅官方文档: https://webkit.org/blog/6784/new-video-policies-for-ios/



iOS 9及之前



从iOS 6.1起,不能再在iPad上自动播放视频。 / p>

我假设他们为什么停用自动播放功能?



好吧,由于许多设备所有者在他们的设备上具有数据使用/带宽限制,我认为苹果认为用户自己应该决定何时启动带宽使用。






经过一番研究,我发现苹果文档中关于iOS设备上自动播放的以下摘录,以确认我的假设:


苹果决定禁止在iOS设备上通过脚本和属性实现自动播放视频



在Safari中,在iOS上(对于所有设备,包括iPad),用户可能在蜂窝网络上,并且每个数据单元收费,preload和
自动播放功能已停用。在用户启动之前无法加载数据 - Apple文档


这是 Safari HTML5参考页 了解为何无法在iOS上的Safari中播放嵌入媒体:


警告:为防止用户在
上通过蜂窝网络进行未经授权的下载,用户的费用,嵌入式媒体无法在
中自动播放。Safari在iOS上 - 用户始终启动播放。控制器是
自动提供的iPhone或iPod touch一旦在
播放启动,但对于iPad您必须设置controls属性或
提供使用JavaScript的控制器。







这意味着(就代码而言)是JavaScript的 play / code> play()之前, / code>和 load() load()方法由用户操作(例如点击事件)触发。



基本上,用户启动的播放按钮可以工作,但
an onLoad =play()

例如,这将播放电影:

 < input type =buttonvalue =Playonclick =document.myMovie.play()> 

但是以下操作对iOS无效:

 < body onload =document.myMovie.play()> 


The <video> tags autoplay="autoplay" attribute works fine in Safari.

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();
    }
}

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.

Moreover, calling $("#periscopevideo").get(0).play() from an click via onClick works too.

Is there any restrictions by Apple in regard to autoplay? (I'm running iOS 5+ by the way).

解决方案

iOS 10 update

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).

To see a full list of these restrictions, see the official docs: https://webkit.org/blog/6784/new-video-policies-for-ios/

iOS 9 and before

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?

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.


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 has made the decision to disable the automatic playing of video on iOS devices, through both script and attribute implementations.

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.

Here is a separate warning featured on the Safari HTML5 Reference page about why embedded media cannot be played in Safari on iOS:

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.


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).

Basically, a user-initiated play button works, but an onLoad="play()" event does not.

For example, this would play the movie:

<input type="button" value="Play" onclick="document.myMovie.play()">

Whereas the following would do nothing on iOS:

<body onload="document.myMovie.play()">

这篇关于您可以在iPad上自动播放HTML5视频吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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