1

I've been searching for a good hour for a solution. Video autoplays and loops fine on browsers. But on iphone or ipad doesnt work.

<div id="about-player"></div>
                <script>
                  var tag = document.createElement('script');
                  tag.src = "https://www.youtube.com/iframe_api";
                  var firstScriptTag = document.getElementsByTagName('script')[0];
                  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

                  var player;
                  function onYouTubeIframeAPIReady() {
                    player = new YT.Player('about-player', {
                        videoId: 'ZyYGXrfeoK8',
                        playerVars: {
                            modestbranding: 0,
                            autoplay: 1,
                            controls: 0,
                            showinfo: 0,
                            wmode: 'transparent',
                            branding: 0,
                            rel: 0,
                            autohide: 0,
                            playlist: 'ZyYGXrfeoK8',
                            inline: 1,
                            origin: window.location.origin
                        },
                        events: {
                            'onReady': onPlayerReady,
                            'onStateChange': onPlayerStateChange
                        }
                      });
                    }
                    function onPlayerReady(event) {
                        event.target.playVideo();
                    }
                    var done = false;
                    function onPlayerStateChange(event) {
                        if (event.data == YT.PlayerState.PLAYING && !done) {
                            setTimeout(stopVideo, 300000);
                            done = true;
                        }
                    }
                    function stopVideo() {
                        player.stopVideo();
                    }
                </script>

Is it possible to autoplay a youtube video on IOS devices? If so what changes to my code do I need to make this happen.

1 Answers1

2

Based from this link, autoplay cannot be done on iOS devices (iPhone, iPad, iPod touch) and Android.

Apple wants to avoid eventually unnecessary traffic on their mobile devices - that affects only the autoplay functionality

Also from this thread,

It can't be done. For various reasons (including, but not limited to data usage), Apple doesn't allow auto-playing of videos.

abielita
  • 13,147
  • 2
  • 17
  • 59