From 283c35e6c72321e2376fd0b7314ee9ccb9a73aab Mon Sep 17 00:00:00 2001 From: Techywarrior Date: Fri, 3 May 2013 21:02:46 -0700 Subject: [PATCH] moved playlist functionality into mediaplayer --- dashboard-ui/scripts/mediaplayer.js | 70 ++++++++++++++++++++++++++--- dashboard-ui/scripts/playlist.js | 67 ++++++++------------------- 2 files changed, 82 insertions(+), 55 deletions(-) diff --git a/dashboard-ui/scripts/mediaplayer.js b/dashboard-ui/scripts/mediaplayer.js index fe41a83a3b..68055a8ea6 100644 --- a/dashboard-ui/scripts/mediaplayer.js +++ b/dashboard-ui/scripts/mediaplayer.js @@ -8,6 +8,14 @@ var currentMediaElement; var currentProgressInterval; + if (typeof(self.playing) == 'undefined') { + self.playing = ''; + } + + if (typeof(self.queue) == 'undefined') { + self.queue = []; + } + function endsWith(text, pattern) { text = text.toLowerCase(); @@ -87,7 +95,7 @@ $(".itemAudio").on("ended", function () { MediaPlayer.stopAudio(item.Id); - Playlist.playNext(); + MediaPlayer.queuePlayNext(); }); $(".itemAudio").on("volumechange", function () { @@ -96,6 +104,8 @@ $(".itemAudio").on("play", updateAudioProgress(item.Id)); + MediaPlayer.nowPlaying(item); + return $('audio', nowPlayingBar)[0]; } @@ -235,8 +245,6 @@ (this).addEvent("play", updateProgress); (this).addEvent("ended", function () { - //MediaPlayer.stopVideo(); - //Playlist.playNext(); MediaPlayer.stop(); }); @@ -390,19 +398,69 @@ }; - self.canQueue = function (mediaType) { + + + self.nowPlaying = function (item) { + self.playing = item; + }; + + self.canQueue = function (mediaType) { 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) { ApiClient.getItem(Dashboard.getCurrentUserId(), itemId).done(function (item) { - Playlist.add(item); + self.queueAdd(item); }); }; self.playNext = function (itemId) { ApiClient.getItem(Dashboard.getCurrentUserId(), itemId).done(function (item) { - Playlist.addNext(item); + self.queueAddNext(item); }); }; diff --git a/dashboard-ui/scripts/playlist.js b/dashboard-ui/scripts/playlist.js index 5f61b550cc..d15f249237 100644 --- a/dashboard-ui/scripts/playlist.js +++ b/dashboard-ui/scripts/playlist.js @@ -3,55 +3,9 @@ function playlist() { 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; } @@ -69,7 +23,22 @@ Dashboard.showLoadingMsg(); $("#queueTable").html(''); - $.each(Playlist.queue, function(i, item){ + + //currently playing item + if (MediaPlayer.playing) { + var html = ''; + html += ''; + html += ''; + html += '' + MediaPlayer.playing.Name + ''; + html += '' + MediaPlayer.playing.Album + ''; + html += '' + ticks_to_human(MediaPlayer.playing.RunTimeTicks) + ''; + html += '' + LibraryBrowser.getUserDataIconsHtml(MediaPlayer.playing) + ''; + html += ''; + html += ''; + $("#queueTable").append(html); + } + + $.each(MediaPlayer.queue, function(i, item){ var html = ''; var name = item.Name; @@ -89,12 +58,12 @@ } html += ''; - html += ''; + html += ''; html += '' + name + ''; html += '' + seriesName + ''; html += '' + ticks_to_human(item.RunTimeTicks) + ''; html += '' + LibraryBrowser.getUserDataIconsHtml(item) + ''; - html += 'remove'; + html += 'remove'; html += ''; $("#queueTable").append(html);