S
S
Sergey Miller2017-12-04 23:24:20
YouTube
Sergey Miller, 2017-12-04 23:24:20

How to track when a youtube video stopped?

I want to write a function that will be executed when the YouTube video has stopped (not pause) / or when it has reached the end (like the same). I can't figure out how to track when it stopped.

tried like this but doesn't work:

if(
jQuery(this)[0].contentWindow.postMessage('{"event":"command","func":"stopVideo","args":""}', '*')){
$('.testimImg').fadeIn(500);
//тут делаем что хотим;
};


Can you help me figure out how to do it right?
api youtube included.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artemy, 2017-12-05
Kaydash @kayart

The YouTube frames API has a special onStateChange
event. Your code will look something like this:
player.addEventListener("onStateChange", function(state) {
if (state === 0) {
// code that fires after the end of the video
}
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question