sync updates

This commit is contained in:
Luke Pulverenti 2015-03-08 00:37:48 -05:00
parent 46293e3e6d
commit b013e62f2e

View File

@ -528,11 +528,10 @@
function getOptimalMediaSource(mediaType, versions) { function getOptimalMediaSource(mediaType, versions) {
var optimalVersion; var optimalVersion;
var bitrateSetting = AppSettings.maxStreamingBitrate();
if (mediaType == 'Video') { if (mediaType == 'Video') {
var bitrateSetting = AppSettings.maxStreamingBitrate();
var maxAllowedWidth = self.getMaxPlayableWidth(); var maxAllowedWidth = self.getMaxPlayableWidth();
optimalVersion = versions.filter(function (v) { optimalVersion = versions.filter(function (v) {
@ -547,6 +546,13 @@
return self.canPlayVideoDirect(v, videoStream, audioStream, null, maxAllowedWidth, bitrateSetting); return self.canPlayVideoDirect(v, videoStream, audioStream, null, maxAllowedWidth, bitrateSetting);
})[0];
} else {
optimalVersion = versions.filter(function (v) {
return canPlayAudioMediaSourceDirect(v);
})[0]; })[0];
} }
@ -565,59 +571,49 @@
self.stop(); self.stop();
} }
if (item.MediaType !== 'Audio' && item.MediaType !== 'Video') {
throw new Error("Unrecognized media type");
}
var mediaSource; var mediaSource;
if (item.MediaType === "Video") { ApiClient.getJSON(ApiClient.getUrl('Items/' + item.Id + '/PlaybackInfo', {
userId: Dashboard.getCurrentUserId()
ApiClient.getJSON(ApiClient.getUrl('Items/' + item.Id + '/PlaybackInfo', { })).done(function (result) {
userId: Dashboard.getCurrentUserId()
})).done(function (result) { if (validatePlaybackInfoResult(result)) {
if (validatePlaybackInfoResult(result)) { mediaSource = getOptimalMediaSource(item.MediaType, result.MediaSources);
mediaSource = getOptimalMediaSource(item.MediaType, result.MediaSources);;
if (mediaSource) { if (mediaSource) {
self.currentMediaSource = mediaSource;
self.currentItem = item; self.currentMediaSource = mediaSource;
self.currentItem = item;
if (item.MediaType === "Video") {
self.currentMediaElement = self.playVideo(item, self.currentMediaSource, startPosition); self.currentMediaElement = self.playVideo(item, self.currentMediaSource, startPosition);
self.currentDurationTicks = self.currentMediaSource.RunTimeTicks; self.currentDurationTicks = self.currentMediaSource.RunTimeTicks;
self.updateNowPlayingInfo(item); self.updateNowPlayingInfo(item);
if (callback) { } else if (item.MediaType === "Audio") {
callback();
} self.currentMediaElement = playAudio(item, self.currentMediaSource, startPosition);
} else { self.currentDurationTicks = self.currentMediaSource.RunTimeTicks;
showPlaybackInfoErrorMessage('NoCompatibleStream');
} }
if (callback) {
callback();
}
} else {
showPlaybackInfoErrorMessage('NoCompatibleStream');
} }
});
} else if (item.MediaType === "Audio") {
mediaSource = getOptimalMediaSource(item.MediaType, item.MediaSources);
if (mediaSource) {
self.currentItem = item;
self.currentMediaSource = mediaSource;
self.currentMediaElement = playAudio(item, self.currentMediaSource, startPosition);
self.currentDurationTicks = self.currentMediaSource.RunTimeTicks;
if (callback) {
callback();
}
} else {
showPlaybackInfoErrorMessage('NoCompatibleStream');
} }
} else { });
throw new Error("Unrecognized media type");
}
}; };
function validatePlaybackInfoResult(result) { function validatePlaybackInfoResult(result) {
@ -1349,6 +1345,31 @@
return $('.mediaPlayerAudio'); return $('.mediaPlayerAudio');
} }
function canPlayAudioMediaSourceDirect(mediaSource) {
var sourceContainer = (mediaSource.Container || '').toLowerCase();
if (sourceContainer == 'mp3' ||
(sourceContainer == 'aac' && supportsAac)) {
for (var i = 0, length = mediaSource.MediaStreams.length; i < length; i++) {
var stream = mediaSource.MediaStreams[i];
if (stream.Type == "Audio") {
// Stream statically when possible
if (stream.BitRate <= 320000) {
return true;
}
break;
}
}
}
return false;
}
var supportsAac = document.createElement('audio').canPlayType('audio/aac').replace(/no/, ''); var supportsAac = document.createElement('audio').canPlayType('audio/aac').replace(/no/, '');
function playAudio(item, mediaSource, startPositionTicks) { function playAudio(item, mediaSource, startPositionTicks) {
@ -1365,25 +1386,7 @@
}; };
var sourceContainer = (mediaSource.Container || '').toLowerCase(); var sourceContainer = (mediaSource.Container || '').toLowerCase();
var isStatic = false; var isStatic = canPlayAudioMediaSourceDirect(mediaSource);
if (sourceContainer == 'mp3' ||
(sourceContainer == 'aac' && supportsAac)) {
for (var i = 0, length = mediaSource.MediaStreams.length; i < length; i++) {
var stream = mediaSource.MediaStreams[i];
if (stream.Type == "Audio") {
// Stream statically when possible
if (stream.BitRate <= 320000) {
isStatic = true;
}
break;
}
}
}
var outputContainer = isStatic ? sourceContainer : 'mp3'; var outputContainer = isStatic ? sourceContainer : 'mp3';
var audioUrl = ApiClient.getUrl('Audio/' + item.Id + '/stream.' + outputContainer, $.extend({}, baseParams, { var audioUrl = ApiClient.getUrl('Audio/' + item.Id + '/stream.' + outputContainer, $.extend({}, baseParams, {