Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Video Background not playing Safari on iPhone

I have the video background plugin for site origin page builder (Wordpress) and I have uploaded a background video (MP4 and WEBM formats). The file sizes are around 35mb and 17mb respectively.

I have tested on a couple of iPhones running up to date iOS with safari and the video is not autoplaying as it should (only showing fallback image).

Video Code:

<video id="so_bgvideo_5df3a8b601042" 
class="so_video_bg jquery-background-video is-playing is-visible" 
loop="" autoplay="" playsinline="" muted="" data-bgvideo="" 
poster="https://mywebsite.com/fallback-image.jpg" 
data-bgvideo-fade-in="500" data-bgvideo-pause-after="120" 
data-bgvideo-show-pause-play="true" 
data-bgvideo-pause-play-x-pos="right"
data-bgvideo-pause-play-y-pos="top" 
style="min-width: auto; min-height:auto; width: 100%; height: auto;
position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
transition-duration: 500ms;">
<source src="https://mywebsite.com/video.mp4" type="video/mp4">
<source src="https://mywebsite.com/video.webm" type="video/webm">
</video>

As far as I can tell the video contains the attributes required via Safari (and it plays fine on Safari desktop).

Can anyone please advise a fix to get it working on Safari mobile?

like image 674
YorkieMagento Avatar asked Dec 13 '19 15:12

YorkieMagento


People also ask

Why Safari on iOS is not showing my HTML5 video poster?

Double-Click home button to get the task switcher outside of Safari, tap and hold on the safari icon until the kill button shows. Open safari (restarted). At this point, if you load the test page (the one with just one video), the poster will show.

How do I enable HTML5 in Safari iPhone?

If you turn on the Develop menu in Safari (Preferences » Advanced » check the box), you get the option to choose the User Agent string Safari will hand to a site to tell what browser it is. From the Develop menu, Choose User Agent » Mobile Safari 3.2. 2 - iPad and the site will switch to HTML5 if it supports it.

Does Safari support HTML5 iPhone?

Safari supports HTML5. If YouTube video doesn't play, try either disabling or uninstalling extensions like ClickToFlash.


1 Answers

Safari doesn't allow autoplay of video on these 2 scenarios

  1. when "muted" config not set
  2. when iphone is in battery saving mode or in low battery

To achieve autoplay, enable mute and autoplay in both attribute and via js like

<video id="BgVideo" muted autoplay>

<script>
var bgvideo = document.getElementById("BgVideo");
bgvideo.muted = true;
bgvideo.play();
</script>
like image 119
Ganeshkumar K Avatar answered Nov 15 '22 09:11

Ganeshkumar K