最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Playing video automatically on Safari won't work - Stack Overflow

programmeradmin0浏览0评论

When I open my website in Safari (desktop) my video usually starts automatically. I know in the past it already won't play automatic on iPad or iPhone but not on desktop.

It's like Safari set new rules. Is there a way to play the videos automatically? Because there is a website that I've found that still automatically play videos on their website on Safari.

Thanks in advance!

When I open my website in Safari (desktop) my video usually starts automatically. I know in the past it already won't play automatic on iPad or iPhone but not on desktop.

It's like Safari set new rules. Is there a way to play the videos automatically? Because there is a website that I've found that still automatically play videos on their website on Safari.

Thanks in advance!

Share Improve this question edited Aug 21, 2019 at 9:42 Pingolin 3,4177 gold badges27 silver badges43 bronze badges asked Mar 29, 2018 at 9:06 Sebbe77Sebbe77 1531 gold badge1 silver badge6 bronze badges 6
  • Possible duplicate of Muted autoplay videos stop playing in Safari 11.0 – Turnip Commented Mar 29, 2018 at 9:08
  • var ua = navigator.userAgent.toLowerCase(); var is_safari = (ua.indexOf("safari/") > -1 && ua.indexOf("chrome") < 0); if(is_safari) { var video = document.getElementById('#video-element-id'); setTimeout(function() { video.play(); }, 50); } – Sebbe77 Commented Mar 29, 2018 at 9:21
  • when i use this code it just give one error still... TypeError: null is not an object (evaluating 'video.play') – Sebbe77 Commented Mar 29, 2018 at 9:21
  • document.getElementById('#video-element-id') should not have a #. Change to document.getElementById('video-element-id'). This is assuming that your video has the id "video-element-id" – Turnip Commented Mar 29, 2018 at 9:22
  • i still get the old error : [Error] Unhandled Promise Rejection: NotAllowedError (DOM Exception 35): The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission. (x107) – Sebbe77 Commented Mar 29, 2018 at 9:29
 |  Show 1 more comment

3 Answers 3

Reset to default 5

This can be circumvented using the following properties:

<video muted playsinline autoplay></video>

But autoplaying with the sound turned on is indeed not possible anymore. More information can be found on webkit.org.

I have Mojave and found a solution that worked for a site I use often.

One can go to the top bar menu:

Safari Preferences -> The 'Websites' (tab heading) -> Auto-Play (left side)

As the default websites Auto-Play option is Stop Media with Sound, this strategy introduced the permission issue.

Allow media from that site. One can turn it on at the bottom of that box for all sites.

There is a simpler way in the same menu next to Safari Prefrences, called 'Settings for This Website' -- it allows you to make that same setting, and a few others rather than having to poke around the rest of the Settings box.

Clearly that means a user has to allow it.

The site where I found a working example: https://support.shadowhealth.com/hc/en-us/articles/360009548313-Audio-issues-in-Safari

I did post the way to do it above so the site is not needed if they ever take it down, but they did do nice screen shots. I put it here for handy reference.

To deal with browsers who 'wander' to your location, you would need to provide a button to launch videos or audio clips.

This could be due to the fact that apple is blocking this add-on https://techcrunch.com/2017/06/05/auto-play-block/

发布评论

评论列表(0)

  1. 暂无评论