0

Hello I'm displaying a youtube video in a div full screen. It change size on resize window and the most important thing it load on demand and play/pause if it's on the viewport or not.

To control the viewport and lazy loading I'm using viewportchecker So, ViewportChecker check if the DIV is in the viewport, if YES it start the funcion playPause1, the function will start the video or pause it in case the video is already being played.

 $('#Wraptv1').viewportChecker({
     callbackFunction: playPause1,
     offset: 300,
     repeat: true,
 });

Everything works very good but sometimes the video is not respecting the startSeconds parameter mostly if the page is loaded when the video DIV is outside the viewport. In this case the first video should start in the second 30 (as tou can see below in the video parameters) but it starts from the second 0.

video parameters:

 var ystv1 = [{
         'videoId': 'Gc2en3nHxA4',
         'startSeconds': 30,
         'endSeconds': 45,
         'suggestedQuality': 'hd720'
     },{
         'videoId': 'Gc2en3nHxA4',
         'startSeconds': 65,
         'endSeconds': 90,
         'suggestedQuality': 'hd720'
     }, ],

Here the code example: https://codepen.io/ysanmiguel/pen/WEGwqO

any help or suggestion to fix this problem or improve the code? thank you very much.

ysanmiguel
  • 451
  • 1
  • 4
  • 20

1 Answers1

0

Same scenario is required in this SO post.

Here is the main problem of the user:

For my project I need to be able to control the current time that the video is playing. I have searched the You-Tube API notes and data but could not find a parameter nor a function that enables me to set the current time of the video (There is a GET for the current time but not a set).

You may also try the answer in this SO post and visit the following documents.

First you need a JS reference to the Player object. For a quick start, please take a look at the following Question:

With this reference you can do:

player.seekTo(42); //Go to 42 seconds
MαπμQμαπkγVπ.0
  • 5,887
  • 1
  • 27
  • 65