What are the limits of "user initiated" playback events on html5 mobile video player

It seems to be a common complaint that mobile devices won't automatically play video or audio. According to Apple's developer library, it is specifically disabled:

In Safari on iOS (for all devices including iPad), where the user can be on the cellular network and charge per unit of data, preloading and autoplay are disabled. No data is loaded until the user initiates it. This means that the JavaScript play () and load () methods are also inactive until the user starts playing, unless the play () or load () method is called by user action. In other words, the custom play button works, but the onLoad = "play ()" event doesn't.

What is allowed for direct user action to trigger a replay event. My problem is that I have video thumbnails that, when clicked, load the video element into place and should play after loading them. On mobile, the user needs to double click to make the video play, which is not very good. I'm upset because my user actually triggers the game action, but there are several other events that happen in between. I started testing another user triggered event to see what the scope or limits of that apple is causing "direct user action".

I found that this code triggered a play event:

$(".clickElement").click(function(){
    $("video").get(0).play();
});

      

until that happened:

$(".clickElement").click(function(){
    setTimeout(function(){
        $("video").get(0).play();
    },0);
});

      

the same was for different timeouts and when setInterval was used instead.

My question is, what / how does apple define direct user action? Obviously, timeouts and intervals are not straightforward enough. Is there a way to fire an event "directly" from the user and allow enough time for my video element to enter?

+3


source to share





All Articles