From a1b70df3ccac7064b39863a078d17657ed0aedb5 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 28 Jan 2016 01:42:27 -0500 Subject: [PATCH] better handling of playback stop --- dashboard-ui/scripts/mediaplayer.js | 36 +++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/dashboard-ui/scripts/mediaplayer.js b/dashboard-ui/scripts/mediaplayer.js index 4ccf5b95c6..4e76c35244 100644 --- a/dashboard-ui/scripts/mediaplayer.js +++ b/dashboard-ui/scripts/mediaplayer.js @@ -569,7 +569,7 @@ // viblast can help us here //return true; - return window.MediaSource != null && !browserInfo.firefox; + return window.MediaSource != null; }; self.changeStream = function (ticks, params) { @@ -1518,6 +1518,11 @@ Events.off(mediaRenderer, 'ended', self.playNextAfterEnded); + var stopTranscoding = false; + if (!currentProgressInterval) { + stopTranscoding = true; + } + mediaRenderer.stop(); Events.trigger(mediaRenderer, "ended"); @@ -1530,10 +1535,17 @@ self.currentMediaRenderer = null; self.currentItem = null; - self.currentMediaSource = null; + self.currentSubtitleStreamIndex = null; self.streamInfo = {}; + self.currentMediaSource = null; + + if (stopTranscoding) { + ApiClient.stopActiveEncodings(); + } + + } else { self.currentMediaRenderer = null; self.currentItem = null; @@ -1767,14 +1779,24 @@ Events.trigger(self, 'playstatechange', [state]); }; - window.addEventListener("beforeunload", function () { - + function onAppClose() { // Try to report playback stopped before the browser closes - if (self.currentItem && self.currentMediaRenderer && currentProgressInterval) { + if (self.currentItem && self.currentMediaRenderer) { - self.onPlaybackStopped.call(self.currentMediaRenderer); + if (currentProgressInterval) { + + self.onPlaybackStopped.call(self.currentMediaRenderer); + } else { + ApiClient.stopActiveEncodings(); + } } - }); + } + + window.addEventListener("beforeunload", onAppClose); + + if (browserInfo.safari) { + document.addEventListener("pause", onAppClose); + } function sendProgressUpdate() {