Hey I think it works for single videos CZTEROOKI DON'T PULL THIS I SWEAR TO GOD

This commit is contained in:
calzoneman 2013-07-02 15:01:12 -04:00
parent e3afacd415
commit c3b782b04a
2 changed files with 43 additions and 26 deletions

View file

@ -782,7 +782,8 @@ Channel.prototype.broadcastPlaylistMeta = function() {
var total = 0; var total = 0;
var iter = this.playlist.items.first; var iter = this.playlist.items.first;
while(iter !== null) { while(iter !== null) {
total += iter.media.seconds; if(iter.media !== null)
total += iter.media.seconds;
iter = iter.next; iter = iter.next;
} }
var timestr = formatTime(total); var timestr = formatTime(total);
@ -1225,29 +1226,23 @@ Channel.prototype.addMedia = function(data, user, callback) {
Channel.prototype.enqueueList = function(data, user) { Channel.prototype.enqueueList = function(data, user) {
var pl = data.list; var pl = data.list;
var chan = this; var chan = this;
// Queue in reverse order for qnext this.playlist.addMediaList(data, function(err, item) {
if(data.pos == "next") { if(err) {
var i = pl.length; if(err === true)
var cback = function() { err = false;
i--; if(user)
if(i > 0) { user.socket.emit("queueFail", err);
pl[i].pos = "next"; return;
chan.enqueue(pl[i], user, cback);
}
} }
this.enqueue(pl[0], user, cback); else {
} chan.sendAll("queue", {
else { item: item.pack(),
var i = 0; after: item.prev ? item.prev.uid : "prepend"
var cback = function() { });
i++; chan.broadcastPlaylistMeta();
if(i < pl.length) { chan.cacheMedia(item.media);
pl[i].pos = "end";
chan.enqueue(pl[i], user, cback);
}
} }
this.enqueue(pl[i], user, cback); });
}
} }
Channel.prototype.tryQueuePlaylist = function(user, data) { Channel.prototype.tryQueuePlaylist = function(user, data) {

View file

@ -71,9 +71,13 @@ Playlist.prototype.queueAction = function(data) {
Playlist.prototype.dump = function() { Playlist.prototype.dump = function() {
var arr = this.items.toArray(); var arr = this.items.toArray();
var pos = arr.indexOf(this.current); var pos = 0;
if(pos < 0) for(var i in arr) {
pos = 0; if(arr[i].uid == this.current.uid) {
pos = i;
break;
}
}
var time = 0; var time = 0;
if(this.current) if(this.current)
@ -133,6 +137,14 @@ Playlist.prototype.add = function(item, pos) {
} }
Playlist.prototype.addMedia = function(data, callback) { Playlist.prototype.addMedia = function(data, callback) {
if(this.lock) {
this.queueAction({
fn: "addMedia",
args: arguments
});
return;
}
this.lock = true;
var pos = "append"; var pos = "append";
if(data.pos == "next") { if(data.pos == "next") {
if(!this.current) if(!this.current)
@ -145,6 +157,7 @@ Playlist.prototype.addMedia = function(data, callback) {
InfoGetter.getMedia(data.id, data.type, function(err, media) { InfoGetter.getMedia(data.id, data.type, function(err, media) {
if(err) { if(err) {
callback(err, null); callback(err, null);
pl.lock = false;
return; return;
} }
@ -155,10 +168,19 @@ Playlist.prototype.addMedia = function(data, callback) {
callback(true, null); callback(true, null);
else else
callback(false, it); callback(false, it);
pl.lock = false;
}); });
} }
Playlist.prototype.remove = function(uid, callback) { Playlist.prototype.remove = function(uid, callback) {
if(this.lock) {
this.queueAction({
fn: "remove",
args: arguments
});
return;
}
this.lock = true;
var item = this.items.find(uid); var item = this.items.find(uid);
if(this.items.remove(uid)) { if(this.items.remove(uid)) {
if(item == this.current) if(item == this.current)
@ -166,6 +188,7 @@ Playlist.prototype.remove = function(uid, callback) {
if(callback) if(callback)
callback(); callback();
} }
this.lock = false;
} }
Playlist.prototype.move = function(from, after, callback) { Playlist.prototype.move = function(from, after, callback) {
@ -179,7 +202,6 @@ Playlist.prototype.move = function(from, after, callback) {
this.lock = true; this.lock = true;
this._move(from, after, callback); this._move(from, after, callback);
this.lock = false; this.lock = false;
this.lock = false;
} }
Playlist.prototype._move = function(from, after, callback) { Playlist.prototype._move = function(from, after, callback) {