Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Detect when video has changed - YouTube iFrame API

$
0
0

I have some kind of slider with a YouTube playlist in the background. I'd like to know when the video has changed, so I can change the slider text to the right text.

I've searched the API page (https://developers.google.com/youtube/iframe_api_reference#Events) and can't seem to find an event that fires when the video changes. Is there one?

Here's my code until now.

var tag = document.createElement('script');tag.src = "https://www.youtube.com/iframe_api";var firstScriptTag = document.getElementsByTagName('script')[0];firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);window.player;var player;var playlistVideos = new Array();jQuery('#playlistSlider span').each(function(){    playlistVideos.push(jQuery(this).html());})//console.log(playlistVideos)function onYouTubePlayerAPIReady() {    player = new YT.Player('playlistSlider', {        height: '390',        width: '640',        loadPlaylist:{            listType:'playlist',            list:playlistVideos,            index:parseInt(0),            //suggestedQuality:'small'        },        events: {'onReady': onPlayerReady,            //'onStateChange': onPlayerStateChange        },    });}function onPlayerReady(event) {    event.target.loadPlaylist(playlistVideos);    event.target.mute();    event.target.setLoop(true);}

A bonus would also be to know what is the current video playing (index).


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>