// Load the YouTube player API var tag = document.createElement('script'); tag.src = 'https://www.youtube.com/watch?v=S0Pd9VibNCU'; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); // Create a global variable for the player var player; // Set the video ID and player options var videoId = 'S0Pd9VibNCU'; var playerOptions = { height: '360', width: '640', videoId: videoId, events: { 'onReady': onPlayerReady, }, }; // When the player is ready, start playback and schedule repeat function onPlayerReady(event) { // Start playback event.target.playVideo(); // Set the duration and repeat interval in seconds var duration = 30; var repeatInterval = 5; // Repeat the video every repeatInterval seconds setInterval(function() { // Check if the video has ended if (event.target.getCurrentTime() >= duration) { // Seek to the beginning of the video and play it again event.target.seekTo(0); event.target.playVideo(); } }, repeatInterval * 1000); } // Create the player object when the YouTube API is ready function onYouTubePlayerAPIReady() { player = new YT.Player('player', playerOptions); }

Commentaires

Posts les plus consultés de ce blog

ne pas supprimer