From 85ac0ffcd7c9d4ed901f1b8b3c69f7c5c30d1ea1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 11 Jul 2013 16:43:37 -0400 Subject: [PATCH] support sending out playstate commands --- ApiClient.js | 18 +++++++ dashboard-ui/scripts/remotecontrol.js | 71 +++++++++++++++++++++++++-- packages.config | 2 +- 3 files changed, 86 insertions(+), 5 deletions(-) diff --git a/ApiClient.js b/ApiClient.js index b1c4a7a633..637e2e549a 100644 --- a/ApiClient.js +++ b/ApiClient.js @@ -3271,6 +3271,24 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { url: url }); }; + + self.sendPlayStateCommand = function (sessionId, command, options) { + + if (!sessionId) { + throw new Error("null sessionId"); + } + + if (!command) { + throw new Error("null command"); + } + + var url = self.getUrl("Sessions/" + sessionId + "/Playing/" + command, options || {}); + + return self.ajax({ + type: "POST", + url: url + }); + }; } }(jQuery, navigator, window.JSON, window.WebSocket, setTimeout); diff --git a/dashboard-ui/scripts/remotecontrol.js b/dashboard-ui/scripts/remotecontrol.js index a6b4ab7b14..2703d65ff4 100644 --- a/dashboard-ui/scripts/remotecontrol.js +++ b/dashboard-ui/scripts/remotecontrol.js @@ -682,6 +682,63 @@ }); } + + $('.btnStop', popup).on('click', function () { + + var id = $('#selectSession', popup).val(); + + ApiClient.sendPlayStateCommand(id, 'Stop'); + }); + + $('.btnPause', popup).on('click', function () { + + var id = $('#selectSession', popup).val(); + + ApiClient.sendPlayStateCommand(id, 'Pause'); + }); + + $('.btnPlay', popup).on('click', function () { + + var id = $('#selectSession', popup).val(); + + ApiClient.sendPlayStateCommand(id, 'Unpause'); + }); + + $('.btnNextTrack', popup).on('click', function () { + + var id = $('#selectSession', popup).val(); + + ApiClient.sendPlayStateCommand(id, 'NextTrack'); + }); + + $('.btnPreviousTrack', popup).on('click', function () { + + var id = $('#selectSession', popup).val(); + + ApiClient.sendPlayStateCommand(id, 'PreviousTrack'); + }); + + $("#positionSlider", popup).on("slidestart", function () { + + this.isSliding = true; + + }).on("slidestop", function () { + + var id = $('#selectSession', popup).val(); + + var percent = $(this).val(); + + var duration = parseInt($(this).attr('data-duration')); + + var position = duration * percent / 100; + + ApiClient.sendPlayStateCommand(id, 'Seek', + { + SeekPosition: parseInt(position) + }); + + this.isSliding = false; + }); } function getPlaybackHtml() { @@ -700,7 +757,7 @@ html += ''; html += ''; - html += ''; + html += ''; html += ''; html += '
'; @@ -757,11 +814,11 @@ type: 'Primary', tag: item.PrimaryImageTag }); - + if (!img || img.src.toLowerCase().indexOf(imgUrl.toLowerCase()) == -1) { imageContainer.html(''); } - + } else { imageContainer.hide(); } @@ -771,7 +828,13 @@ var percent = duration ? 100 * time / duration : 0; - $('#positionSlider', elem).val(percent).slider('refresh'); + var slider = $('#positionSlider', elem); + + if (!slider[0].isSliding) { + slider.val(percent).slider('refresh'); + } + + slider.attr('data-duration', duration); $('.nowPlayingTime', elem).html(Dashboard.getDisplayTime(time)); $('.duration', elem).html(Dashboard.getDisplayTime(duration)); diff --git a/packages.config b/packages.config index d09b4a2cd2..5dd14404a2 100644 --- a/packages.config +++ b/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file