From cfbb089031b857e7abc0249db3818231cef4362f Mon Sep 17 00:00:00 2001 From: Techywarrior Date: Sun, 28 Apr 2013 10:36:20 -0700 Subject: [PATCH] fixed github #208 - Web client - Playback check-ins are still sent if video fails to play fixed github #209 - Web client - playback check-ins not sent for audio --- dashboard-ui/scripts/mediaplayer.js | 33 +++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/dashboard-ui/scripts/mediaplayer.js b/dashboard-ui/scripts/mediaplayer.js index 3549b8aa30..c5edddc170 100644 --- a/dashboard-ui/scripts/mediaplayer.js +++ b/dashboard-ui/scripts/mediaplayer.js @@ -57,17 +57,28 @@ }); $(".itemAudio").on("ended", function () { + MediaPlayer.stopAudio(item.Id); + Playlist.playNext(); }); $(".itemAudio").on("volumechange", function () { - localStorage.setItem("volume", this.volume); }); + $(".itemAudio").on("play", updateAudioProgress(item.Id)); + return $('audio', nowPlayingBar)[0]; } + function updateAudioProgress(itemId) { + ApiClient.reportPlaybackStart(Dashboard.getCurrentUserId(), itemId); + + currentProgressInterval = setInterval(function () { + ApiClient.reportPlaybackProgress(Dashboard.getCurrentUserId(), itemId, $(".itemAudio").currentTime); + }, 30000); + } + function playVideo(items, startPosition) { //stop/kill videoJS if (currentMediaElement) self.stop(); @@ -193,7 +204,7 @@ localStorage.setItem("volume", this.volume()); }); - (this).addEvent("play", updateProgress); + (this).addEvent("play", updateProgress(item.Id)); (this).addEvent("ended", function () { MediaPlayer.stopVideo(); @@ -201,13 +212,14 @@ Playlist.playNext(); }); - ApiClient.reportPlaybackStart(Dashboard.getCurrentUserId(), item.Id); }); return $('video', nowPlayingBar)[0]; } - function updateProgress() { + function updateProgress(itemId) { + ApiClient.reportPlaybackStart(Dashboard.getCurrentUserId(), itemId); + currentProgressInterval = setInterval(function () { var player = _V_("videoWindow"); @@ -361,6 +373,8 @@ //player.tech.destroy(); player.destroy(); } else { + self.stopAudio(); + elem.pause(); elem.src = ""; } @@ -390,6 +404,17 @@ } } + self.stopAudio = function () { + var itemString = $(".itemAudio source").attr('src').match(new RegExp("Audio/[0-9a-z\-]+", "g")); + var itemId = itemString[0].replace("Audio/", ""); + + ApiClient.reportPlaybackStopped(Dashboard.getCurrentUserId(), itemId, $(".itemAudio").currentTime); + + if (currentProgressInterval) { + clearTimeout(currentProgressInterval); + } + } + self.isPlaying = function () { return currentMediaElement; };