Safari 11上的视频自动播放 [英] Video autoplay on Safari 11

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

问题描述

您好,视频不再能够在safari 11上自动播放.以下是我的代码,该代码可在Chrome上正常运行,因为必须将其静音.它仅显示海报图像.任何帮助.

Hi have noticed video does not auto play on safari 11 anymore. Below is my code it works on Chrome as it has to be muted. It just shows the poster image. Any Help.

<video width="100%" poster="poster_url.png" autoplay muted playsinline>
<source src="video_url.mp4" type="video/mp4">
</video>

推荐答案

以下内容在OSX 10.12.6的Safari 11.1.2上自动为我播放

The below autoplays for me on Safari 11.1.2 on OSX 10.12.6

<video width="100%" poster="poster_url.png" autoplay muted playsinline>
<source src="http://download.blender.org/peach/trailer/trailer_480p.mov" type="video/mp4">
</video>

规则确实经常更改,并且用户或组织也可以设置自己的偏好,因此Safari团队建议您始终检查代码以查看视频是否能够自动播放:

The rules do changes quite often and it is also possible for a user or organisation to set their own preferences, so the Safari team recommend that you check in your code always to see if the video is able to auto play:

var promise = document.querySelector('video').play();

if (promise !== undefined) {
    promise.catch(error => {
        // Auto-play was prevented
        // Show a UI element to let the user manually start playback
    }).then(() => {
        // Auto-play started
    });
}

撰写本文时,此处有更多详细信息:

More details here at the time of writing:

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

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