moved playlist functionality into mediaplayer

This commit is contained in:
Techywarrior 2013-05-03 21:02:46 -07:00
parent 75ff5c8f43
commit 283c35e6c7
2 changed files with 82 additions and 55 deletions

View File

@ -8,6 +8,14 @@
var currentMediaElement; var currentMediaElement;
var currentProgressInterval; var currentProgressInterval;
if (typeof(self.playing) == 'undefined') {
self.playing = '';
}
if (typeof(self.queue) == 'undefined') {
self.queue = [];
}
function endsWith(text, pattern) { function endsWith(text, pattern) {
text = text.toLowerCase(); text = text.toLowerCase();
@ -87,7 +95,7 @@
$(".itemAudio").on("ended", function () { $(".itemAudio").on("ended", function () {
MediaPlayer.stopAudio(item.Id); MediaPlayer.stopAudio(item.Id);
Playlist.playNext(); MediaPlayer.queuePlayNext();
}); });
$(".itemAudio").on("volumechange", function () { $(".itemAudio").on("volumechange", function () {
@ -96,6 +104,8 @@
$(".itemAudio").on("play", updateAudioProgress(item.Id)); $(".itemAudio").on("play", updateAudioProgress(item.Id));
MediaPlayer.nowPlaying(item);
return $('audio', nowPlayingBar)[0]; return $('audio', nowPlayingBar)[0];
} }
@ -235,8 +245,6 @@
(this).addEvent("play", updateProgress); (this).addEvent("play", updateProgress);
(this).addEvent("ended", function () { (this).addEvent("ended", function () {
//MediaPlayer.stopVideo();
//Playlist.playNext();
MediaPlayer.stop(); MediaPlayer.stop();
}); });
@ -390,19 +398,69 @@
}; };
self.nowPlaying = function (item) {
self.playing = item;
};
self.canQueue = function (mediaType) { self.canQueue = function (mediaType) {
return mediaType == "Audio"; return mediaType == "Audio";
}; };
self.queueAdd = function (item) {
self.queue.push(item);
};
self.queueRemove = function (elem) {
var index = $(elem).attr("data-queue-index");
self.queue.splice(index, 1);
$(elem).parent().parent().remove();
return false;
};
self.queuePlay = function (elem) {
var index = $(elem).attr("data-queue-index");
MediaPlayer.play(new Array(self.queue[index]));
self.queue.splice(index, 1);
};
self.queuePlayNext = function (item) {
if (typeof self.queue[0] != "undefined") {
MediaPlayer.play(new Array(self.queue[0]));
self.queue.shift();
}
};
self.queueAddNext = function (item) {
if (typeof self.queue[0] != "undefined") {
self.queue.unshift(item);
}else {
self.queueAdd(item);
}
};
self.inQueue = function (item) {
$.each(MediaPlayer.queue, function(i, queueItem){
if (item.Id == queueItem.Id) {
return true;
}
});
return false;
};
self.playLast = function (itemId) { self.playLast = function (itemId) {
ApiClient.getItem(Dashboard.getCurrentUserId(), itemId).done(function (item) { ApiClient.getItem(Dashboard.getCurrentUserId(), itemId).done(function (item) {
Playlist.add(item); self.queueAdd(item);
}); });
}; };
self.playNext = function (itemId) { self.playNext = function (itemId) {
ApiClient.getItem(Dashboard.getCurrentUserId(), itemId).done(function (item) { ApiClient.getItem(Dashboard.getCurrentUserId(), itemId).done(function (item) {
Playlist.addNext(item); self.queueAddNext(item);
}); });
}; };

View File

@ -3,55 +3,9 @@
function playlist() { function playlist() {
var self = this; var self = this;
if (typeof(self.queue) == 'undefined') {
self.queue = [];
}
self.add = function (item) {
self.queue.push(item);
};
self.remove = function (elem) {
var index = $(elem).attr("data-queue-index");
self.queue.splice(index, 1);
$(elem).parent().parent().remove();
return false;
};
self.play = function (elem) {
var index = $(elem).attr("data-queue-index");
MediaPlayer.play(new Array(self.queue[index]));
self.queue.splice(index, 1);
};
self.playNext = function (item) {
if (typeof self.queue[0] != "undefined") {
MediaPlayer.play(new Array(self.queue[0]));
self.queue.shift();
}
};
self.addNext = function (item) {
if (typeof self.queue[0] != "undefined") {
self.queue.unshift(item);
}else {
self.add(item);
}
};
self.inQueue = function (item) {
$.each(Playlist.queue, function(i, queueItem){
if (item.Id == queueItem.Id) {
return true;
}
});
return false;
};
return self; return self;
} }
@ -69,7 +23,22 @@
Dashboard.showLoadingMsg(); Dashboard.showLoadingMsg();
$("#queueTable").html(''); $("#queueTable").html('');
$.each(Playlist.queue, function(i, item){
//currently playing item
if (MediaPlayer.playing) {
var html = '';
html += '<tr>';
html += '<td></td>';
html += '<td>' + MediaPlayer.playing.Name + '</td>';
html += '<td>' + MediaPlayer.playing.Album + '</td>';
html += '<td>' + ticks_to_human(MediaPlayer.playing.RunTimeTicks) + '</td>';
html += '<td>' + LibraryBrowser.getUserDataIconsHtml(MediaPlayer.playing) + '</td>';
html += '<td></td>';
html += '</tr>';
$("#queueTable").append(html);
}
$.each(MediaPlayer.queue, function(i, item){
var html = ''; var html = '';
var name = item.Name; var name = item.Name;
@ -89,12 +58,12 @@
} }
html += '<tr>'; html += '<tr>';
html += '<td><img src="css/images/media/playCircle.png" style="height: 28px;cursor:pointer;" data-queue-index="'+i+'" onclick="Playlist.play(this)" /></td>'; html += '<td><img src="css/images/media/playCircle.png" style="height: 28px;cursor:pointer;" data-queue-index="'+i+'" onclick="MediaPlayer.queuePlay(this)" /></td>';
html += '<td>' + name + '</td>'; html += '<td>' + name + '</td>';
html += '<td>' + seriesName + '</td>'; html += '<td>' + seriesName + '</td>';
html += '<td>' + ticks_to_human(item.RunTimeTicks) + '</td>'; html += '<td>' + ticks_to_human(item.RunTimeTicks) + '</td>';
html += '<td>' + LibraryBrowser.getUserDataIconsHtml(item) + '</td>'; html += '<td>' + LibraryBrowser.getUserDataIconsHtml(item) + '</td>';
html += '<td><a href="" data-queue-index="'+i+'" onclick="Playlist.remove(this)">remove</a></td>'; html += '<td><a href="" data-queue-index="'+i+'" onclick="MediaPlayer.queueRemove(this)">remove</a></td>';
html += '</tr>'; html += '</tr>';
$("#queueTable").append(html); $("#queueTable").append(html);