HTML视频无法在Safari浏览器中播放 [英] HTML video not playing in Safari browser

查看:149
本文介绍了HTML视频无法在Safari浏览器中播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在Mozilla&中正常工作铬合金.但是在Safari中,视频无法播放.

Below code is working fine in Mozilla & Chrome. But in Safari the video doesn't play.

<video id="v-control" width="100%" autoplay="autoplay" loop>
    <source src="assets/img/web home page banner.mp4" type="video/mp4" 
    media="all and (max-width: 480px)">
    <source src="video-small.webm" type="video/webm" media="all and 
    (max-width: 480px)">
    <source src="assets/img/web home page banner.mp4" type="video/mp4">
    <source src="video.webm" type="video/webm">
</video>

我已尝试将preload用作视频标签,如果添加controls,则应单击播放"按钮.我不需要视频的任何控件,因此我删除了控件.

I have tried preload for the video tag and If I add controls I should click on Play button. I dont need any controls for the video so I have removed controls.

推荐答案

Safari在去年开始启动,默认情况下会阻止自动播放带有音轨的视频.据我所知,他们从未对此进行具体宣传,但是我相信这是以下更改的一部分:

Safari has started (in the last year) preventing videos with audio tracks from auto-playing by default. They never specifically publicised this as far as I'm aware, however I believe it was part of the following changes:

Safari 11还通过打开Safari的新网站"偏好设置面板,使用户可以控制允许哪些网站自动播放视频和音频

Safari 11 also gives users control over which websites are allowed to auto-play video and audio by opening Safari’s new "Websites" preferences pane

(来源)

唯一真正的解决方法是从视频中删除音轨,或者默认情况下将其静音.

The only real workarounds for this are to either remove the audio track from the video, or have it muted by default.

<video id="v-control" width="100%" autoplay="autoplay" loop muted>

如果您的服务器可以检测到请求者的浏览器,则可以将其仅应用到Safari,而其他浏览器则保持不变.

If your server can detect the requester's browser, you can apply this to just Safari, leaving other browsers as they were before.

这篇关于HTML视频无法在Safari浏览器中播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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