From 68579f3a451b910ffa47ed9cc7414a5e0338105f Mon Sep 17 00:00:00 2001 From: Ludovic Barman Date: Sun, 11 May 2014 13:47:28 +0200 Subject: Working version YoutubePlayer --- app/index.html | 6 ++++++ app/js/yt_musicsearch.js | 18 ++++++++++++++---- videosearch_n_play.html | 13 ++++++++++++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app/index.html b/app/index.html index 8bb6176..905840a 100644 --- a/app/index.html +++ b/app/index.html @@ -45,6 +45,12 @@
  • {{song.label}}
  • + + + +
    diff --git a/app/js/yt_musicsearch.js b/app/js/yt_musicsearch.js index fcc52db..82ad741 100644 --- a/app/js/yt_musicsearch.js +++ b/app/js/yt_musicsearch.js @@ -18,12 +18,22 @@ function searchClicked() document.documentElement.firstChild.appendChild(script); } - - function newMusic(id) + + var musicTimer; + + function startSongWithDuration(id, duration) { $('#ytplayer').attr('src', 'https://www.youtube.com/embed/'+id+'?autoplay=1&modestbranding=1'); + console.log("Starting music "+id+", timer="+duration); + musicTimer = setInterval(changeSong, duration * 1000); } - + + function changeSong() + { + alert("Done"); + clearInterval(musicTimer); + } + function getAllMatchingIds(data) { var feed = data.feed; @@ -44,7 +54,7 @@ function searchClicked() for (var i = 0; i < results.length; i++) { //html.push('
  • ', '', results[i].title, '(', results[i].duration, ')', '
  • '); - html.push('
  • ', '', results[i].title, '', '
  • '); + html.push('
  • ', '', results[i].title, '', '
  • '); } html.push(''); document.getElementById('videoResultsDiv').innerHTML = html.join(''); diff --git a/videosearch_n_play.html b/videosearch_n_play.html index 8a8f854..fb58843 100644 --- a/videosearch_n_play.html +++ b/videosearch_n_play.html @@ -31,9 +31,18 @@ } - function newMusic(id) + var songFinished; + function newMusic(id, duration) { $('#ytplayer').attr('src', 'https://www.youtube.com/embed/'+id+'?autoplay=1&modestbranding=1'); + songFinished = setTimer(nextSong, duration * 1000); + console.log("Setting timer for "+duration+" seconds"); + } + + function nextSong() + { + clearTimer(songFinished); + console.log("Bingo !"); } function getAllMatchingIds(data) @@ -60,6 +69,8 @@ html.push(''); document.getElementById('videoResultsDiv').innerHTML = html.join(''); } + + -- cgit v1.2.3