From 85010d35e09c874e8af5151367295df7dc792020 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 6 Apr 2014 14:00:37 -0400 Subject: [PATCH 1/2] encapsulate CC limits --- dashboard-ui/scripts/chromecast.js | 49 ++++++++++++++++++------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/dashboard-ui/scripts/chromecast.js b/dashboard-ui/scripts/chromecast.js index d2b7f5d159..bca82b8327 100644 --- a/dashboard-ui/scripts/chromecast.js +++ b/dashboard-ui/scripts/chromecast.js @@ -229,16 +229,17 @@ clearInterval(this.timer); }; - function getMaxVideoAudioChannels() { - return 6; - } + function getCodecLimits() { + return { - function getMaxAudioChannels() { - return 2; - } + maxVideoAudioChannels: 6, + maxAudioChannels: 2, + maxVideoLevel: 41, + maxWidth: 1920, + maxHeight: 1080, + maxSampleRate: 44100 - function getMaxVideoLevel() { - return 41; + }; } function canDirectStream(mediaType, mediaSource, maxBitrate) { @@ -248,6 +249,8 @@ return false; } + var codecLimits = getCodecLimits(); + if (mediaType == "Audio") { return ['mp3', 'aac'].indexOf(mediaSource.Container || '') != -1; @@ -268,15 +271,15 @@ return false; } - if (!videoStream.Level || videoStream.Level > getMaxVideoLevel()) { + if (!videoStream.Level || videoStream.Level > codecLimits.maxVideoLevel) { return false; } - if (!videoStream.Width || videoStream.Width > 1920) { + if (!videoStream.Width || videoStream.Width > codecLimits.maxWidth) { return false; } - if (!videoStream.Height || videoStream.Height > 1080) { + if (!videoStream.Height || videoStream.Height > codecLimits.maxHeight) { return false; } @@ -297,12 +300,18 @@ return false; } - var maxChannels = isVideo ? getMaxVideoAudioChannels() : getMaxAudioChannels(); + var codecLimits = getCodecLimits(); + + var maxChannels = isVideo ? codecLimits.maxVideoAudioChannels : codecLimits.maxAudioChannels; if (!audioStream.Channels || audioStream.Channels > maxChannels) { return false; } + if (!audioStream.SampleRate || audioStream.SampleRate > codecLimits.maxSampleRate) { + return false; + } + return true; } @@ -540,11 +549,13 @@ var url; + var codecLimits = getCodecLimits(); + if (item.MediaType == 'Audio') { url = ApiClient.serverAddress() + '/mediabrowser/audio/' + item.Id + '/stream.' + mediaSourceInfo.streamContainer + '?'; url += '&static=' + mediaSourceInfo.isStatic.toString(); - url += '&maxaudiochannels=' + getMaxAudioChannels(); + url += '&maxaudiochannels=' + codecLimits.maxAudioChannels; if (startTimeTicks) { url += '&startTimeTicks=' + startTimeTicks.toString(); @@ -554,7 +565,7 @@ url += '&audiobitrate=' + Math.min(maxBitrate, 320000).toString(); } - url += '&audiosamplerate=44100'; + url += '&audiosamplerate=' + codecLimits.maxSampleRate; url += '&mediasourceid=' + mediaSourceInfo.mediaSource.Id; return url; @@ -564,7 +575,7 @@ url = ApiClient.serverAddress() + '/mediabrowser/videos/' + item.Id + '/stream.' + mediaSourceInfo.streamContainer + '?'; url += 'static=' + mediaSourceInfo.isStatic.toString(); - url += '&maxaudiochannels=' + getMaxVideoAudioChannels(); + url += '&maxaudiochannels=' + codecLimits.maxVideoAudioChannels; if (startTimeTicks) { url += '&startTimeTicks=' + startTimeTicks.toString(); @@ -578,15 +589,15 @@ } url += '&profile=high'; - url += '&level=' + getMaxVideoLevel(); + url += '&level=' + codecLimits.maxVideoLevel; - url += '&maxwidth=1920'; - url += '&maxheight=1080'; + url += '&maxwidth=' + codecLimits.maxWidth; + url += '&maxheight=' + codecLimits.maxHeight; url += '&videoCodec=h264'; url += '&audioCodec=aac'; - url += '&audiosamplerate=44100'; + url += '&audiosamplerate=' + codecLimits.maxSampleRate; url += '&mediasourceid=' + mediaSourceInfo.mediaSource.Id; return url; From 1a1efc1646bfd991a707502469e644afd6229d83 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 6 Apr 2014 22:06:09 -0400 Subject: [PATCH 2/2] fixes #317 - Pausing for too long stops media & hitting play goes back to the previous restore point --- dashboard-ui/scripts/mediaplayer-video.js | 40 +++++++++++------------ dashboard-ui/scripts/mediaplayer.js | 13 +++++++- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/dashboard-ui/scripts/mediaplayer-video.js b/dashboard-ui/scripts/mediaplayer-video.js index dce49d2c18..5569a461e2 100644 --- a/dashboard-ui/scripts/mediaplayer-video.js +++ b/dashboard-ui/scripts/mediaplayer-video.js @@ -22,7 +22,6 @@ var fullscreenExited = false; var idleState = true; var remoteFullscreen = false; - var videoMenuVisible = false; self.initVideoPlayer = function () { video = playVideo(item, mediaSource, startPosition, user); @@ -263,7 +262,7 @@ video.removeClass("cursor-active").addClass("cursor-inactive"); videoControls.removeClass("active").addClass("inactive"); }, 4000); - }; + } function requestFullScreen(element) { @@ -276,7 +275,7 @@ enterFullScreen(); } - }; + } function changeHandler(event) { @@ -284,7 +283,7 @@ fullscreenExited = self.isFullScreen() == false; }); - }; + } function enterFullScreen() { @@ -294,7 +293,7 @@ remoteFullscreen = true; - }; + } function exitFullScreenToWindow() { @@ -304,7 +303,7 @@ remoteFullscreen = false; - }; + } function toggleFlyout(flyout, button) { @@ -334,14 +333,14 @@ hideFlyout(flyout); } - }; + } function hideFlyout(flyout) { flyout.slideUp().empty(); $(document.body).off("mousedown.hidesearchhints"); - }; + } function getChaptersFlyoutHtml() { @@ -400,7 +399,7 @@ } return html; - }; + } function getAudioTracksHtml() { @@ -468,7 +467,7 @@ } return html; - }; + } function getSubtitleTracksHtml() { @@ -541,7 +540,7 @@ } return html; - }; + } function getQualityFlyoutHtml() { @@ -582,7 +581,7 @@ } return html; - }; + } function getInitialSubtitleStreamIndex(mediaStreams, user) { @@ -621,7 +620,7 @@ } return null; - }; + } function getInitialAudioStreamIndex(mediaStreams, user) { @@ -651,7 +650,7 @@ // Just use the first audio stream return audioStreams[0]; - }; + } function getVideoQualityOptions(mediaStreams) { @@ -729,8 +728,8 @@ options[selectedIndex].selected = true; return options; - }; - + } + function playVideo(item, mediaSource, startPosition, user) { var mediaStreams = mediaSource.MediaStreams || []; @@ -922,7 +921,7 @@ }, 300); // Pause stop timer - this.pauseStop = setTimeout(function () { + self.pauseStop = setTimeout(function () { self.stop(); }, 5 * 60 * 1000); // 5 minutes @@ -936,8 +935,7 @@ }, 300); // Remove pause setop timer - window.clearTimeout(this.pauseStop); - delete this.pauseStop; + self.clearPauseStop(); }).on("timeupdate", function () { @@ -948,6 +946,8 @@ }).on("error", function () { + self.clearPauseStop(); + $("html").css("cursor", "default"); $(".ui-loader").hide(); self.resetEnhancements(); @@ -1038,6 +1038,6 @@ currentMediaSource = mediaSource; return videoElement[0]; - }; + } }; })(); \ No newline at end of file diff --git a/dashboard-ui/scripts/mediaplayer.js b/dashboard-ui/scripts/mediaplayer.js index 299a94e8ab..516c10cde1 100644 --- a/dashboard-ui/scripts/mediaplayer.js +++ b/dashboard-ui/scripts/mediaplayer.js @@ -60,8 +60,19 @@ return Math.floor(10000000 * (mediaElement || currentMediaElement).currentTime) + self.startTimeTicksOffset; }; + self.clearPauseStop = function() { + + if (self.pauseStop) { + console.log('clearing pause stop timer'); + window.clearTimeout(self.pauseStop); + self.pauseStop = null; + } + }; + self.onPlaybackStopped = function () { + self.clearPauseStop(); + $(this).off('ended.playbackstopped'); self.currentTimeElement.empty(); @@ -1159,7 +1170,7 @@ var getItemFields = "MediaSources,Chapters"; - self.getCurrentTargetInfo = function() { + self.getCurrentTargetInfo = function () { return self.getTargets()[0]; }; }