title: How can I prevent a user from fast-forwarding/scrubbing/skipping ahead in an embedded YouTube video?
body: <p>I'd like to present an embedded HTML YouTube video to a user, and prevent them from fast-forwarding or skipping to the end of the video. I can get most of the way there by using YouTube's API to remove the player controls (see code snippet), however on iOS it's still possible to get the video to run in the native player (along with its scrub controls) by pinching-to-zoom. Is there any easy way of doing this? </p>
  
  <p>I should note, I've also tried using a .m4v video as a file instead which gives more options in HTML5, but that's not an ideal solution for me right now (bandwidth and download issues).</p>
  
  <pre class="lang-js prettyprint-override"><code>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('player', {
            height: '390',
            width: '640',
            videoId: 'KjLYjf4B7xQ',
            events: {
              'onReady': onPlayerReady
            },
           playerVars: {rel: 0, 
                        showinfo: 0, 
                        controls: 0, 
                        disablekb: 1,
                        modestbranding: 1,
                        cc_load_policy: 1,
                        playsinline: 1}
          });
        }
  
        function onPlayerReady(event) {
          event.target.playVideo();
        }
  </code></pre>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div id="player"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>(I tried getting this to run as a snippet but there were cross-origin errors.)</p>
  
  <p>Any help is appreciated. Thanks!</p>
  
  <p>Edit: in addition to Mauricio's answer I also had to add a button to start the video, because the user can't click inside the video to start it. Something like this:</p>
  
  <pre><code>  function onPlayerReady(event) {
      event.target.playVideo();
  
      var playButton = document.getElementById("play-button");
      playButton.addEventListener("click", function() {
         player.playVideo();
      });
    }
  </code></pre>
  
  <p>And for the button:</p>
  
  <pre><code>&lt;button id="play-button"&gt;Play Video&lt;/button&gt;
  </code></pre>