Bryce77
Bryce77

Reputation: 315

YouTube JS API: play by random time point on button click

I am trying to achieve playing a movie with YouTube JS API. There should be multiple time point in a single movie, so clicking on a button it would randomly pick any timepoint from the movie and start playing from there.

Here is my POC

<iframe id="ytplayer" 
type="text/html" width="720" height="405"
src="https://www.youtube.com/embed/M7lc1UVf-VE?rel=0&amp;showinfo=0&amp;theme=light" 
frameborder="0" allowfullscreen>

Upvotes: 1

Views: 1517

Answers (1)

Paul Fitzgerald
Paul Fitzgerald

Reputation: 12129

You can use the embedded youtube start parameter to start the video at a given time. Create a function to generate a random number and then assign this random number to the start parameter.

See the jsfiddle attached as a demo. http://jsfiddle.net/y6dkwrov/6/

Every time you click the button it will change the start time to the video from a different point.

Let me know if this is the effect you are looking for.

Upvotes: 2

Related Questions