E
E
enchikiben2013-08-16 13:11:46
iOS
enchikiben, 2013-08-16 13:11:46

How did YouTube make videos autoplay in iPad and iPhone?

Good afternoon! The subject itself, or how it can be done in the video tag

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
Alexey Zhurbitsky, 2013-08-16
@blo

Fake click trick worked on ancient versions of iOS

        function fakeClick(fn) {
            var $a = $('<a href="#" id="fakeClick"></a>');
                $a.bind("click", function(e) {
                    e.preventDefault();
                    fn();
                });

            $("body").append($a);

            var evt, 
                el = $("#fakeClick").get(0);

            if (document.createEvent) {
                evt = document.createEvent("MouseEvents");
                if (evt.initMouseEvent) {
                    evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
                    el.dispatchEvent(evt);
                }
            }

            $(el).remove();
        }

        $(function() {
            var video = $("#someVideo").get(0);

            fakeClick(function() {
                video.play();
            });
        });

stackoverflow.com/questions/3009888/autoplay-audio-files-on-an-ipad-with-html5
But as far as I understand, at least with iOS 6.x, this no longer works.
On YouTube, things are a little trickier. When you open youtube.com, you see a list of videos and click on one. At this point, there is actually no transition to another page (navigation happens through a hash in the URL). Since we stayed on the same page, we can bind the start of playback to a click, most likely something similar to the example from the documentation is used:
 <input type="button" value="Play" onclick="document.myMovie.play()">

For the sake of interest, enter a direct url to some video in the browser on the iPad and do not click on the page. Will auto play start?

M
m08pvv, 2013-08-16
@m08pvv

www.w3schools.com/tags/att_video_autoplay.asp - is it?

R
rozhik, 2013-08-16
@rozhik

Is it autoplay?
In my opinion, one click is required. And in the context of the click handler, you can start playing the video.

M
Makito, 2013-08-16
@Makito

I just did video.play(); and it works, but there the call was in the execution context after changing the slide on the screen, maybe this somehow affected the work.

E
enchikiben, 2013-08-16
@EnChikiben

doing like this

<script>
myVid=document.getElementById("video1");
myVid.play();
</script> 

on the
Mozilla/5.0 (iPad; U; CPU OS 6_1 like Mac OS X; ja-jp) AppleWebKit/536.26 (KHTML, like Gecko) Version/6 Mobile/10B141 Safari/8536.25

does not play ... as I understand it, you even have a newer version

A
An, 2013-09-01
@Flanker_4

And look at the js from this site here is a
link to the first movie that came across.
On my second pad with iOS 6.1, the video automatically plays (by the way, it's sooooo annoying)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question