I want my youtube videos to always play from the beginning, not where it left off last time

Viewed 7066

When I load a youtube video into my web page, I want it to default to playing from the beginning. I'm using javascript code to control it and I need it to start there initially. Every time I reload the page, though, the video plays where it left off and I can't test my script.

1 Answers

Following the API's documentation this should work:

<div id="player"></div>

<script>
  // The IFrame Player API code should be added here

  var player;
  function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
      videoId: 'UG8DX3LxDb8',
      playerVars: {
         'start': 0
      },
      events: {
        'onReady': onPlayerReady
      }
    });
  }

  function onPlayerReady(event) {
    event.target.playVideo();
  }
</script>

This code generates an iframe showing the video with id 'UG8DX3LxDb8' and the playerVar start tells the API to start at 0 seconds.

Related