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) {
var optimalVersion;
var bitrateSetting = AppSettings.maxStreamingBitrate();
if (mediaType == 'Video') {
var bitrateSetting = AppSettings.maxStreamingBitrate();
var maxAllowedWidth = self.getMaxPlayableWidth();
optimalVersion = versions.filter(function (v) {
@ -547,6 +546,13 @@
return self.canPlayVideoDirect(v, videoStream, audioStream, null, maxAllowedWidth, bitrateSetting);
})[0];
} else {
optimalVersion = versions.filter(function (v) {
return canPlayAudioMediaSourceDirect(v);
})[0];
}
@ -565,9 +571,11 @@
self.stop();
}
var mediaSource;
if (item.MediaType !== 'Audio' && item.MediaType !== 'Video') {
throw new Error("Unrecognized media type");
}
if (item.MediaType === "Video") {
var mediaSource;
ApiClient.getJSON(ApiClient.getUrl('Items/' + item.Id + '/PlaybackInfo', {
userId: Dashboard.getCurrentUserId()
@ -575,49 +583,37 @@
})).done(function (result) {
if (validatePlaybackInfoResult(result)) {
mediaSource = getOptimalMediaSource(item.MediaType, result.MediaSources);;
mediaSource = getOptimalMediaSource(item.MediaType, result.MediaSources);
if (mediaSource) {
self.currentMediaSource = mediaSource;
self.currentItem = item;
if (item.MediaType === "Video") {
self.currentMediaElement = self.playVideo(item, self.currentMediaSource, startPosition);
self.currentDurationTicks = self.currentMediaSource.RunTimeTicks;
self.updateNowPlayingInfo(item);
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) {
@ -1349,6 +1345,31 @@
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/, '');
function playAudio(item, mediaSource, startPositionTicks) {
@ -1365,25 +1386,7 @@
};
var sourceContainer = (mediaSource.Container || '').toLowerCase();
var isStatic = false;
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 isStatic = canPlayAudioMediaSourceDirect(mediaSource);
var outputContainer = isStatic ? sourceContainer : 'mp3';
var audioUrl = ApiClient.getUrl('Audio/' + item.Id + '/stream.' + outputContainer, $.extend({}, baseParams, {