From 808e77923749a9060da422e3bbb927b6a1d45483 Mon Sep 17 00:00:00 2001 From: Klafyvel Date: Sun, 25 Mar 2018 20:23:32 +0200 Subject: [PATCH] affiche la lecture actuelle --- player/templates/player/playlist.html | 54 ++++++++++++++++++--------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/player/templates/player/playlist.html b/player/templates/player/playlist.html index cc6fafa..68f9346 100644 --- a/player/templates/player/playlist.html +++ b/player/templates/player/playlist.html @@ -71,32 +71,45 @@ function onYouTubeIframeAPIReady() { // 4. The API will call this function when the video player is ready. function onPlayerReady(event) { if(tracks.length > 0 && current_link < (tracks.length - 1)) { - current_link += 1 - player.loadVideoById(tracks[current_link]); - event.target.playVideo(); + next(); } setInterval(loadLinks, 5000); } +function play() { + player.loadVideoById(tracks[current_link]); + player.playVideo(); + document.getElementById(tracks[current_link]).classList.add('bg-success'); + document.getElementById(tracks[current_link]).classList.remove('bg-secondary'); +} function next() { if (current_link < (tracks.length -1)) { - current_link += 1 - player.loadVideoById(tracks[current_link]); - event.target.playVideo(); + current_link += 1; + play(); } } function prev() { if (current_link > 0) { - current_link -= 1 - player.loadVideoById(tracks[current_link]); - event.target.playVideo(); + current_link -= 1; + play(); } } +function setCurrent(c) { + if(c > 0 && c < tracks.length) { + current_link = c; + play(); + } +} + +function setCurrentFromToken(token) { + setCurrent(tracks.indexOf(token)); +} + function onPlayerStateChange(event) { if (event.data == YT.PlayerState.ENDED) { - onPlayerReady(); + next(); } } function stopVideo() { @@ -124,16 +137,23 @@ function updateLinks(data) { tracks = []; for (var i=0; iPistes à venir