0

Heyo guys!

I am new to javascript and kind of a noob, That's why I try to use as less js as possible but for this part i really needed it.

I have a fullscreen video and it plays correctly the first time, but I want it to use the Embedded URL again when it reloads. So I made this js.

        function onYouTubeIframeAPIReady() {
          var player;
          player = new YT.Player('video', {
            videoId: 'A3rvUNcueFg', // YouTube Video ID
            playerVars: {
              autoplay: 1,        // Auto-play the video on load
              controls: 0,        // Show pause/play buttons in player
              showinfo: 0,        // Hide the video title
              loop: 1,            // Run the video in a loop
              fs: 1,              // Hide the full screen button
              cc_load_policty: 0, // Hide closed captions
              iv_load_policy: 3,  // Hide the Video Annotations
              autohide: 1,         // Hide video controls when playing
              start: 13,
              end: 295,
              rel: 0,
              playlist: 'A3rvUNcueFg'
            },
            events: {
              onReady: function(e) {
                e.target.mute();
                var Embed = e.target.getVideoEmbedCode();
              }
            }
          });
          YT.PlayerState.ENDED: function(e) {
            var player;
            player = new YT.Player(Embed)
         }

So what I want it to do, I want it to mute (that part works). Then get the embed URL so i can use it to reload the video at the same start point after it ended. Because it now reloads and starts at the beginning.

Thanks in advance, Jeroen

1 Answers1

0

How about including the seekTo option in your video object. You can pass it the number of seconds that you want to skip to start the video at.

function onYouTubeIframeAPIReady() {
      var player;
      var time = //whatever time you want it to start from each loop; NEW CODE
      player = new YT.Player('video', {
        videoId: 'A3rvUNcueFg', // YouTube Video ID
        playerVars: {
          autoplay: 1,        // Auto-play the video on load
          controls: 0,        // Show pause/play buttons in player
          showinfo: 0,        // Hide the video title
          loop: 1,            // Run the video in a loop
          fs: 1,   // Hide the full screen button
          cc_load_policty: 0, // Hide closed captions
          iv_load_policy: 3,  // Hide the Video Annotations
          autohide: 1,         // Hide video controls when playing
          start: 13,
          end: 295,
          rel: 0,
          playlist: 'A3rvUNcueFg'
        },
        events: {
          onReady: function(e) {
            e.target.mute();
            var Embed = e.target.getVideoEmbedCode();
          }
        }
      });
      YT.PlayerState.ENDED: function(e) {
        var player;
        player = new YT.Player(Embed);
        player.seekTo(time);  //NEW CODE
     }

Ref: https://developers.google.com/youtube/iframe_api_reference#Playback_controls

player.seekTo(seconds:Number, allowSeekAhead:Boolean):Void

Korgrue
  • 3,430
  • 1
  • 13
  • 20