Browse Source

get rid of ids array, play next song automatically

raylu 14 years ago
parent
commit
820edebc26
1 changed files with 13 additions and 9 deletions
  1. 13 9
      static/script.js

+ 13 - 9
static/script.js

@@ -1,5 +1,4 @@
 var current_id = '';
-var ids = [];
 var player;
 var litColor = '#eee';
 var dimmedColor = '#555';
@@ -18,9 +17,6 @@ $(document).ready(function () {
 	userElem.change(function () {
 		localStorage['user'] = userElem.val();
 	});
-	for (var i = 0; i < ids.length; i++) {
-		drawBar(ids[i]);
-	}
 	getUpdates();
 });
 
@@ -115,7 +111,15 @@ function onStateChange(state) {
 		interval = setInterval(drawBar, 100, current_id);
 		break;
 	case 0: //ended
+		clearInterval(interval);
 		showPlay(current_id);
+		var songs = $('article section.song');
+		for (var i = 0; i < songs.length - 1; i++) {
+			if (songs[i].id == current_id) {
+				play(songs[i+1].id);
+				break;
+			}
+		}
 	case -1: //unstarted
 	case 2: //paused
 	case 3: //buffering
@@ -134,11 +138,12 @@ function play(yid) {
 		player.seekTo(0, true);
 	}
 	player.playVideo();
-	for (var i = 0; i < ids.length; i++) {
-		if (ids[i] == yid)
-			showPause(ids[i]);
+	var songs = $('article section.song');
+	for (var i = 0; i < songs.length; i++) {
+		if (songs[i].id == yid)
+			showPause(songs[i].id);
 		else
-			showPlay(ids[i]);
+			showPlay(songs[i].id);
 	}
 }
 function pause(yid) {
@@ -293,7 +298,6 @@ function drawAdd(s) {
 					.addClass('clear')
 				)
 			);
-	ids.push(s.yid);
 	drawBar(s.yid);
 }