From c175f461d1f655d69bc1de23ce4e7dd4db52053c Mon Sep 17 00:00:00 2001 From: calzoneman Date: Tue, 2 Apr 2013 10:55:14 -0500 Subject: [PATCH] Fix playlist movement bug (Issue#16) --- channel.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/channel.js b/channel.js index eac5ceadc..fa74831c7 100644 --- a/channel.js +++ b/channel.js @@ -70,7 +70,10 @@ var Channel = function(name) { pl: this.queue }); this.currentPosition = data.currentPosition - 1; - this.playNext(); + if(this.currentPosition < -1) + this.currentPosition = -1; + if(this.queue.length > 0) + this.playNext(); this.opts = data.opts; if(data.filters) { this.filters = new Array(data.filters.length); @@ -750,8 +753,13 @@ Channel.prototype.moveMedia = function(data) { return; var media = this.queue[data.src]; - this.queue.splice(data.dest + 1, 0, media); - this.queue.splice(data.src, 1); + // Took me a while to figure out why the queue was going insane + // Gotta account for when you've copied it to the destination + // but not removed the source yet + var dest = data.dest > data.src ? data.dest + 1 : data.dest; + var src = data.dest > data.src ? data.src : data.src + 1; + this.queue.splice(dest, 0, media); + this.queue.splice(src, 1); this.sendAll("moveVideo", { src: data.src, dest: data.dest