2013-12-17 13:19:23 -07:00
|
|
|
(function (document, setTimeout, clearTimeout, screen, localStorage, $, setInterval, window) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
function mediaPlayer() {
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
var self = this;
|
2013-04-08 21:26:02 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
var testableVideoElement = document.createElement('video');
|
|
|
|
var currentMediaElement;
|
|
|
|
var currentProgressInterval;
|
2013-05-23 13:09:01 -07:00
|
|
|
var currentItem;
|
|
|
|
var curentDurationTicks;
|
2014-01-10 06:52:01 -07:00
|
|
|
var canClientSeek;
|
2014-03-14 14:16:01 -07:00
|
|
|
var currentPlaylistIndex = 0;
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2014-03-20 01:34:54 -07:00
|
|
|
self.currentTimeElement;
|
|
|
|
self.unmuteButton;
|
|
|
|
self.muteButton;
|
|
|
|
self.positionSlider;
|
2014-03-14 14:16:01 -07:00
|
|
|
self.isPositionSliderActive;
|
|
|
|
self.volumeSlider;
|
|
|
|
self.startTimeTicksOffset;
|
2013-06-07 09:06:32 -07:00
|
|
|
self.playlist = [];
|
2014-01-03 21:53:49 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.updateCanClientSeek = function (elem) {
|
2014-01-10 06:52:01 -07:00
|
|
|
var duration = elem.duration;
|
|
|
|
canClientSeek = duration && !isNaN(duration) && duration != Number.POSITIVE_INFINITY && duration != Number.NEGATIVE_INFINITY;
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.updateVolumeButtons = function (vol) {
|
2013-05-23 13:09:01 -07:00
|
|
|
|
|
|
|
if (vol) {
|
2014-03-20 01:34:54 -07:00
|
|
|
self.muteButton.show();
|
|
|
|
self.unmuteButton.hide();
|
2013-05-23 13:09:01 -07:00
|
|
|
} else {
|
2014-03-20 01:34:54 -07:00
|
|
|
self.muteButton.hide();
|
|
|
|
self.unmuteButton.show();
|
2013-05-23 13:09:01 -07:00
|
|
|
}
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.getCurrentTicks = function (mediaElement) {
|
|
|
|
return Math.floor(10000000 * (mediaElement || currentMediaElement).currentTime) + self.startTimeTicksOffset;
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
2013-05-25 21:52:14 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.onPlaybackStopped = function () {
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2013-06-07 10:23:23 -07:00
|
|
|
$(this).off('ended.playbackstopped');
|
|
|
|
|
2014-03-20 01:34:54 -07:00
|
|
|
self.currentTimeElement.empty();
|
2013-05-23 13:09:01 -07:00
|
|
|
|
|
|
|
var endTime = this.currentTime;
|
|
|
|
|
|
|
|
clearProgressInterval();
|
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
var position = Math.floor(10000000 * endTime) + self.startTimeTicksOffset;
|
2013-05-23 13:09:01 -07:00
|
|
|
|
|
|
|
ApiClient.reportPlaybackStopped(Dashboard.getCurrentUserId(), currentItem.Id, position);
|
2013-12-01 13:17:24 -07:00
|
|
|
|
|
|
|
if (currentItem.MediaType == "Video") {
|
|
|
|
ApiClient.stopActiveEncodings();
|
2014-03-14 14:16:01 -07:00
|
|
|
if (self.isFullScreen()) {
|
|
|
|
self.exitFullScreen();
|
|
|
|
}
|
|
|
|
self.resetEnhancements();
|
2013-12-01 13:17:24 -07:00
|
|
|
}
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
2013-07-16 14:55:50 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.playNextAfterEnded = function () {
|
2013-06-07 10:23:23 -07:00
|
|
|
|
|
|
|
$(this).off('ended.playnext');
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2013-07-18 20:12:52 -07:00
|
|
|
self.nextTrack();
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.startProgressInterval = function (itemId) {
|
2013-05-23 13:09:01 -07:00
|
|
|
|
|
|
|
clearProgressInterval();
|
|
|
|
|
2014-01-04 08:41:35 -07:00
|
|
|
var intervalTime = ApiClient.isWebSocketOpen() ? 2000 : 20000;
|
2013-05-23 13:09:01 -07:00
|
|
|
|
|
|
|
currentProgressInterval = setInterval(function () {
|
|
|
|
|
2013-05-23 15:39:51 -07:00
|
|
|
if (currentMediaElement) {
|
|
|
|
sendProgressUpdate(itemId);
|
|
|
|
}
|
2013-04-08 21:26:02 -07:00
|
|
|
|
2013-05-23 13:09:01 -07:00
|
|
|
}, intervalTime);
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
2014-01-10 06:52:01 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.getTranscodingExtension = function () {
|
2014-01-08 21:45:09 -07:00
|
|
|
|
|
|
|
var media = testableVideoElement;
|
2014-01-10 06:52:01 -07:00
|
|
|
|
2014-01-08 21:45:09 -07:00
|
|
|
// safari
|
2014-01-10 06:52:01 -07:00
|
|
|
if (media.canPlayType('application/x-mpegURL').replace(/no/, '') ||
|
|
|
|
media.canPlayType('application/vnd.apple.mpegURL').replace(/no/, '')) {
|
2014-01-08 21:45:09 -07:00
|
|
|
return '.m3u8';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Chrome or IE with plugin installed
|
2014-01-22 10:05:06 -07:00
|
|
|
if (canPlayWebm() && !$.browser.mozilla) {
|
2014-01-08 21:45:09 -07:00
|
|
|
return '.webm';
|
|
|
|
}
|
2014-01-10 06:52:01 -07:00
|
|
|
|
2014-01-08 21:45:09 -07:00
|
|
|
return '.mp4';
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.changeStream = function (ticks, params) {
|
2013-05-23 18:47:07 -07:00
|
|
|
|
|
|
|
var element = currentMediaElement;
|
|
|
|
|
2014-01-10 06:52:01 -07:00
|
|
|
if (canClientSeek && params == null) {
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2013-05-25 18:53:34 -07:00
|
|
|
element.currentTime = ticks / (1000 * 10000);
|
2013-05-23 18:47:07 -07:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2013-05-25 21:52:14 -07:00
|
|
|
params = params || {};
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2013-05-25 21:52:14 -07:00
|
|
|
var currentSrc = element.currentSrc;
|
|
|
|
currentSrc = replaceQueryString(currentSrc, 'starttimeticks', ticks);
|
2014-01-29 14:54:40 -07:00
|
|
|
|
2013-05-25 21:52:14 -07:00
|
|
|
if (params.AudioStreamIndex != null) {
|
|
|
|
currentSrc = replaceQueryString(currentSrc, 'AudioStreamIndex', params.AudioStreamIndex);
|
|
|
|
}
|
|
|
|
if (params.SubtitleStreamIndex != null) {
|
2014-01-29 14:54:40 -07:00
|
|
|
currentSrc = replaceQueryString(currentSrc, 'SubtitleStreamIndex', (params.SubtitleStreamIndex == -1 ? '' : params.SubtitleStreamIndex));
|
2013-05-23 18:47:07 -07:00
|
|
|
}
|
2014-01-10 06:52:01 -07:00
|
|
|
|
2014-01-16 21:53:16 -07:00
|
|
|
var maxWidth = params.MaxWidth || getParameterByName('MaxWidth', currentSrc);
|
|
|
|
var audioStreamIndex = params.AudioStreamIndex == null ? getParameterByName('AudioStreamIndex', currentSrc) : params.AudioStreamIndex;
|
|
|
|
var subtitleStreamIndex = params.SubtitleStreamIndex == null ? getParameterByName('SubtitleStreamIndex', currentSrc) : params.SubtitleStreamIndex;
|
|
|
|
var videoBitrate = parseInt(getParameterByName('VideoBitrate', currentSrc) || '0');
|
|
|
|
var audioBitrate = parseInt(getParameterByName('AudioBitrate', currentSrc) || '0');
|
|
|
|
var bitrate = params.Bitrate || (videoBitrate + audioBitrate);
|
2014-01-08 21:45:09 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
var transcodingExtension = self.getTranscodingExtension();
|
2014-01-16 21:53:16 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
var finalParams = self.getFinalVideoParams(currentItem, maxWidth, bitrate, audioStreamIndex, subtitleStreamIndex, transcodingExtension);
|
2014-01-16 21:53:16 -07:00
|
|
|
currentSrc = replaceQueryString(currentSrc, 'MaxWidth', finalParams.maxWidth);
|
|
|
|
currentSrc = replaceQueryString(currentSrc, 'VideoBitrate', finalParams.videoBitrate);
|
|
|
|
currentSrc = replaceQueryString(currentSrc, 'AudioBitrate', finalParams.audioBitrate);
|
2014-01-29 09:16:24 -07:00
|
|
|
currentSrc = replaceQueryString(currentSrc, 'Static', finalParams.isStatic);
|
2014-01-16 21:53:16 -07:00
|
|
|
|
|
|
|
if (finalParams.isStatic) {
|
|
|
|
currentSrc = currentSrc.replace('.webm', '.mp4').replace('.m3u8', '.mp4');
|
|
|
|
} else {
|
2014-01-29 09:16:24 -07:00
|
|
|
currentSrc = currentSrc.replace('.mp4', transcodingExtension);
|
2014-01-08 21:45:09 -07:00
|
|
|
}
|
2013-05-23 18:47:07 -07:00
|
|
|
|
|
|
|
clearProgressInterval();
|
|
|
|
|
2013-06-07 10:23:23 -07:00
|
|
|
$(element).off('ended.playbackstopped').off('ended.playnext').on("play.onceafterseek", function () {
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.updateCanClientSeek(this);
|
2014-01-10 06:52:01 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
$(this).off('play.onceafterseek').on('ended.playbackstopped', self.onPlaybackStopped).on('ended.playnext', self.playNextAfterEnded);
|
2013-07-16 14:55:50 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.startProgressInterval(currentItem.Id);
|
2013-05-23 18:47:07 -07:00
|
|
|
sendProgressUpdate(currentItem.Id);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-12-01 13:17:24 -07:00
|
|
|
ApiClient.stopActiveEncodings().done(function () {
|
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.startTimeTicksOffset = ticks;
|
2013-12-01 13:17:24 -07:00
|
|
|
element.src = currentSrc;
|
2014-03-08 01:09:45 -07:00
|
|
|
|
2013-12-01 13:17:24 -07:00
|
|
|
});
|
2013-05-23 18:47:07 -07:00
|
|
|
}
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
2013-04-30 12:13:06 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.setCurrentTime = function (ticks, item, updateSlider) {
|
2013-05-23 13:09:01 -07:00
|
|
|
|
|
|
|
// Convert to ticks
|
|
|
|
ticks = Math.floor(ticks);
|
|
|
|
|
2013-06-07 10:29:33 -07:00
|
|
|
var timeText = Dashboard.getDisplayTime(ticks);
|
2013-05-23 13:09:01 -07:00
|
|
|
|
|
|
|
if (curentDurationTicks) {
|
|
|
|
|
2013-06-07 10:29:33 -07:00
|
|
|
timeText += " / " + Dashboard.getDisplayTime(curentDurationTicks);
|
2013-05-23 13:09:01 -07:00
|
|
|
|
|
|
|
if (updateSlider) {
|
|
|
|
var percent = ticks / curentDurationTicks;
|
|
|
|
percent *= 100;
|
|
|
|
|
2014-03-20 01:34:54 -07:00
|
|
|
self.positionSlider.val(percent).slider('enable').slider('refresh');
|
2013-04-30 12:13:06 -07:00
|
|
|
}
|
2013-05-24 07:35:15 -07:00
|
|
|
} else {
|
2014-03-20 01:34:54 -07:00
|
|
|
self.positionSlider.slider('disable').slider('refresh');
|
2013-05-24 07:35:15 -07:00
|
|
|
}
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2014-03-20 01:34:54 -07:00
|
|
|
self.currentTimeElement.html(timeText);
|
|
|
|
};
|
2013-04-30 10:21:21 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.canPlayVideoDirect = function (item, videoStream, audioStream, subtitleStream, maxWidth, bitrate) {
|
2014-01-08 13:29:09 -07:00
|
|
|
|
|
|
|
if (item.VideoType != "VideoFile" || item.LocationType != "FileSystem") {
|
2014-01-16 21:53:16 -07:00
|
|
|
console.log('Transcoding because the content is not a video file');
|
2014-01-08 13:29:09 -07:00
|
|
|
return false;
|
|
|
|
}
|
2014-01-29 14:54:40 -07:00
|
|
|
|
2014-01-08 13:29:09 -07:00
|
|
|
if ((videoStream.Codec || '').toLowerCase().indexOf('h264') == -1) {
|
2014-01-16 21:53:16 -07:00
|
|
|
console.log('Transcoding because the content is not h264');
|
2014-01-08 13:29:09 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-16 21:53:16 -07:00
|
|
|
if (audioStream && !canPlayAudioStreamDirect(audioStream)) {
|
2014-03-08 01:09:45 -07:00
|
|
|
console.log('Transcoding because the audio cannot be played directly.');
|
2014-01-16 21:53:16 -07:00
|
|
|
return false;
|
|
|
|
}
|
2014-01-08 13:29:09 -07:00
|
|
|
|
2014-01-16 21:53:16 -07:00
|
|
|
if (subtitleStream) {
|
|
|
|
console.log('Transcoding because subtitles are required');
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-29 14:54:40 -07:00
|
|
|
|
2014-01-16 21:53:16 -07:00
|
|
|
if (!videoStream.Width || videoStream.Width > maxWidth) {
|
|
|
|
console.log('Transcoding because resolution is too high');
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-29 14:54:40 -07:00
|
|
|
|
2014-01-16 21:53:16 -07:00
|
|
|
var videoBitrate = videoStream.BitRate || 0;
|
|
|
|
var audioBitrate = audioStream ? audioStream.BitRate || 0 : null;
|
2014-01-29 14:54:40 -07:00
|
|
|
|
2014-01-16 21:53:16 -07:00
|
|
|
if ((videoBitrate + audioBitrate) > bitrate) {
|
|
|
|
console.log('Transcoding because bitrate is too high');
|
2014-01-08 13:29:09 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-10 06:52:01 -07:00
|
|
|
var extension = item.Path.substring(item.Path.lastIndexOf('.') + 1).toLowerCase();
|
|
|
|
|
|
|
|
if (extension == 'm4v') {
|
|
|
|
return $.browser.chrome;
|
|
|
|
}
|
2014-01-08 13:29:09 -07:00
|
|
|
|
2014-01-08 21:45:09 -07:00
|
|
|
return extension.toLowerCase() == 'mp4';
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
2014-01-08 21:45:09 -07:00
|
|
|
|
2014-03-20 01:34:54 -07:00
|
|
|
self.getFinalVideoParams = function (item, maxWidth, bitrate, audioStreamIndex, subtitleStreamIndex, transcodingExtension) {
|
2014-01-08 21:45:09 -07:00
|
|
|
|
2014-03-20 01:34:54 -07:00
|
|
|
var videoStream = (item.MediaStreams || []).filter(function (stream) {
|
|
|
|
return stream.Type === "Video";
|
|
|
|
})[0];
|
2014-01-16 21:53:16 -07:00
|
|
|
|
2014-03-20 01:34:54 -07:00
|
|
|
var audioStream = (item.MediaStreams || []).filter(function (stream) {
|
|
|
|
return stream.Index === audioStreamIndex;
|
|
|
|
})[0];
|
2014-01-16 21:53:16 -07:00
|
|
|
|
2014-03-20 01:34:54 -07:00
|
|
|
var subtitleStream = (item.MediaStreams || []).filter(function (stream) {
|
|
|
|
return stream.Index === subtitleStreamIndex;
|
|
|
|
})[0];
|
2014-01-29 14:54:40 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
var canPlayDirect = self.canPlayVideoDirect(item, videoStream, audioStream, subtitleStream, maxWidth, bitrate);
|
2014-01-08 13:29:09 -07:00
|
|
|
|
2014-01-16 21:53:16 -07:00
|
|
|
var audioBitrate = bitrate >= 700000 ? 128000 : 64000;
|
2014-01-08 13:29:09 -07:00
|
|
|
|
2014-01-16 21:53:16 -07:00
|
|
|
var videoBitrate = bitrate - audioBitrate;
|
2014-01-10 06:52:01 -07:00
|
|
|
|
2014-01-16 21:53:16 -07:00
|
|
|
return {
|
2014-01-08 21:45:09 -07:00
|
|
|
|
2014-01-16 21:53:16 -07:00
|
|
|
isStatic: canPlayDirect,
|
|
|
|
maxWidth: maxWidth,
|
|
|
|
audioCodec: transcodingExtension == '.webm' ? 'vorbis' : 'aac',
|
|
|
|
videoCodec: transcodingExtension == '.webm' ? 'vpx' : 'h264',
|
|
|
|
audioBitrate: audioBitrate,
|
|
|
|
videoBitrate: videoBitrate
|
|
|
|
};
|
2014-01-08 13:29:09 -07:00
|
|
|
}
|
|
|
|
|
2014-01-22 19:19:04 -07:00
|
|
|
self.canPlay = function (item, user) {
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2014-02-20 22:35:56 -07:00
|
|
|
if (item.PlayAccess != 'Full') {
|
2014-01-22 19:19:04 -07:00
|
|
|
return false;
|
|
|
|
}
|
2014-01-29 14:54:40 -07:00
|
|
|
|
2014-03-02 22:11:03 -07:00
|
|
|
if (item.LocationType == "Virtual" || item.IsPlaceHolder) {
|
2014-01-16 10:23:30 -07:00
|
|
|
return false;
|
|
|
|
}
|
2013-11-21 13:48:26 -07:00
|
|
|
if (item.Type == "MusicAlbum" || item.Type == "MusicArtist" || item.Type == "MusicGenre") {
|
2013-06-07 09:06:32 -07:00
|
|
|
return true;
|
|
|
|
}
|
2013-10-26 16:19:26 -07:00
|
|
|
|
|
|
|
if (item.GameSystem == "Nintendo" && item.MediaType == "Game" && item.ProviderIds.NesBox && item.ProviderIds.NesBoxRom) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.GameSystem == "Super Nintendo" && item.MediaType == "Game" && item.ProviderIds.NesBox && item.ProviderIds.NesBoxRom) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-23 18:47:07 -07:00
|
|
|
return self.canPlayMediaType(item.MediaType);
|
|
|
|
};
|
|
|
|
|
2013-11-29 23:07:45 -07:00
|
|
|
self.getPlayUrl = function (item) {
|
2013-10-26 16:19:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
if (item.GameSystem == "Nintendo" && item.MediaType == "Game" && item.ProviderIds.NesBox && item.ProviderIds.NesBoxRom) {
|
|
|
|
|
|
|
|
return "http://nesbox.com/game/" + item.ProviderIds.NesBox + '/rom/' + item.ProviderIds.NesBoxRom;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.GameSystem == "Super Nintendo" && item.MediaType == "Game" && item.ProviderIds.NesBox && item.ProviderIds.NesBoxRom) {
|
|
|
|
|
|
|
|
return "http://snesbox.com/game/" + item.ProviderIds.NesBox + '/rom/' + item.ProviderIds.NesBoxRom;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2013-05-23 18:47:07 -07:00
|
|
|
self.canPlayMediaType = function (mediaType) {
|
|
|
|
|
|
|
|
if (mediaType === "Video") {
|
2014-01-10 06:52:01 -07:00
|
|
|
return true;
|
2013-04-08 21:26:02 -07:00
|
|
|
}
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2013-05-23 18:47:07 -07:00
|
|
|
if (mediaType === "Audio") {
|
2014-01-10 06:52:01 -07:00
|
|
|
return true;
|
2013-04-08 21:16:32 -07:00
|
|
|
}
|
|
|
|
|
2013-04-08 21:26:02 -07:00
|
|
|
return false;
|
2013-04-10 14:03:28 -07:00
|
|
|
};
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
self.play = function (items, startPosition) {
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2013-05-24 19:45:12 -07:00
|
|
|
Dashboard.getCurrentUser().done(function (user) {
|
2013-05-24 18:51:17 -07:00
|
|
|
|
2013-05-24 19:45:12 -07:00
|
|
|
var item = items[0];
|
2013-11-29 23:07:45 -07:00
|
|
|
|
2013-05-24 19:45:12 -07:00
|
|
|
var videoType = (item.VideoType || "").toLowerCase();
|
2013-05-24 18:51:17 -07:00
|
|
|
|
2013-10-12 09:57:27 -07:00
|
|
|
var expirementalText = "This feature is experimental. It may not work at all with some titles. Do you wish to continue?";
|
2013-07-28 07:35:18 -07:00
|
|
|
|
2013-05-24 19:45:12 -07:00
|
|
|
if (videoType == "dvd") {
|
2013-05-24 18:51:17 -07:00
|
|
|
|
2013-07-28 07:35:18 -07:00
|
|
|
self.playWithWarning(items, startPosition, user, "dvdstreamconfirmed", "Dvd Folder Streaming", expirementalText);
|
2013-05-24 18:51:17 -07:00
|
|
|
return;
|
|
|
|
}
|
2013-05-24 19:45:12 -07:00
|
|
|
else if (videoType == "bluray") {
|
2013-05-24 18:51:17 -07:00
|
|
|
|
2013-07-28 07:35:18 -07:00
|
|
|
self.playWithWarning(items, startPosition, user, "bluraystreamconfirmed", "Blu-ray Folder Streaming", expirementalText);
|
2013-05-24 18:51:17 -07:00
|
|
|
return;
|
|
|
|
}
|
2013-05-24 19:45:12 -07:00
|
|
|
else if (videoType == "iso") {
|
|
|
|
|
|
|
|
var isoType = (item.IsoType || "").toLowerCase();
|
|
|
|
|
|
|
|
if (isoType == "dvd") {
|
2013-05-24 18:51:17 -07:00
|
|
|
|
2013-07-28 07:35:18 -07:00
|
|
|
self.playWithWarning(items, startPosition, user, "dvdisostreamconfirmed", "Dvd Iso Streaming", expirementalText);
|
2013-05-24 19:45:12 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (isoType == "bluray") {
|
|
|
|
|
2013-07-28 07:35:18 -07:00
|
|
|
self.playWithWarning(items, startPosition, user, "blurayisostreamconfirmed", "Blu-ray Iso Streaming", expirementalText);
|
2013-05-24 19:45:12 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
self.playInternal(items[0], startPosition, user);
|
|
|
|
self.onPlaybackStarted(items);
|
2013-05-24 19:45:12 -07:00
|
|
|
});
|
2013-05-24 18:51:17 -07:00
|
|
|
};
|
|
|
|
|
2013-07-28 07:35:18 -07:00
|
|
|
self.playWithWarning = function (items, startPosition, user, localStorageKeyName, header, text) {
|
2013-05-24 18:51:17 -07:00
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
// Increment this version when changes are made and we want users to see the prompts again
|
|
|
|
var warningVersion = "2";
|
|
|
|
localStorageKeyName += new Date().getMonth() + warningVersion;
|
2013-07-16 14:55:50 -07:00
|
|
|
|
2013-05-24 18:51:17 -07:00
|
|
|
if (localStorage.getItem(localStorageKeyName) == "1") {
|
2013-06-07 09:06:32 -07:00
|
|
|
|
|
|
|
self.playInternal(items[0], startPosition, user);
|
|
|
|
|
|
|
|
self.onPlaybackStarted(items);
|
|
|
|
|
2013-05-24 18:51:17 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-28 07:35:18 -07:00
|
|
|
Dashboard.confirm(text, header, function (result) {
|
2013-05-24 19:45:12 -07:00
|
|
|
|
2013-05-24 18:51:17 -07:00
|
|
|
if (result) {
|
|
|
|
|
|
|
|
localStorage.setItem(localStorageKeyName, "1");
|
2013-06-07 09:06:32 -07:00
|
|
|
|
|
|
|
self.playInternal(items[0], startPosition, user);
|
|
|
|
|
|
|
|
self.onPlaybackStarted(items);
|
2013-05-24 18:51:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
self.onPlaybackStarted = function (items) {
|
|
|
|
|
|
|
|
self.playlist = items;
|
|
|
|
currentPlaylistIndex = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
self.playInternal = function (item, startPosition, user) {
|
2013-05-24 18:51:17 -07:00
|
|
|
|
2013-07-11 13:25:12 -07:00
|
|
|
if (item == null) {
|
|
|
|
throw new Error("item cannot be null");
|
|
|
|
}
|
2013-07-16 14:55:50 -07:00
|
|
|
|
2013-06-07 10:23:23 -07:00
|
|
|
if (self.isPlaying()) {
|
2013-04-10 14:03:28 -07:00
|
|
|
self.stop();
|
|
|
|
}
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
var mediaElement;
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2014-03-20 01:34:54 -07:00
|
|
|
var mediaControls = $('#nowPlayingBar');
|
2014-03-17 15:37:05 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
if (item.MediaType === "Video") {
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
videoPlayer(self, item, startPosition, user);
|
|
|
|
mediaElement = self.initVideoPlayer();
|
|
|
|
currentItem = item;
|
|
|
|
curentDurationTicks = item.RunTimeTicks;
|
2014-03-20 01:34:54 -07:00
|
|
|
mediaControls = $("#videoControls");
|
2014-03-05 06:56:15 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
} else if (item.MediaType === "Audio") {
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2014-01-10 06:52:01 -07:00
|
|
|
mediaElement = playAudio(item, startPosition);
|
2014-03-20 01:34:54 -07:00
|
|
|
mediaControls.show();
|
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
} else {
|
|
|
|
throw new Error("Unrecognized media type");
|
2013-04-10 14:03:28 -07:00
|
|
|
}
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
currentMediaElement = mediaElement;
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
//display image and title
|
|
|
|
var imageTags = item.ImageTags || {};
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
var url = "";
|
|
|
|
|
2013-05-25 18:53:34 -07:00
|
|
|
if (imageTags.Primary) {
|
|
|
|
|
|
|
|
url = ApiClient.getImageUrl(item.Id, {
|
|
|
|
type: "Primary",
|
|
|
|
height: 80,
|
|
|
|
tag: item.ImageTags.Primary
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if (item.BackdropImageTags && item.BackdropImageTags.length) {
|
2013-04-10 14:03:28 -07:00
|
|
|
|
|
|
|
url = ApiClient.getImageUrl(item.Id, {
|
|
|
|
type: "Backdrop",
|
2013-05-25 18:53:34 -07:00
|
|
|
height: 80,
|
2013-04-10 14:03:28 -07:00
|
|
|
tag: item.BackdropImageTags[0]
|
|
|
|
});
|
|
|
|
} else if (imageTags.Thumb) {
|
|
|
|
|
|
|
|
url = ApiClient.getImageUrl(item.Id, {
|
|
|
|
type: "Thumb",
|
2013-05-25 18:53:34 -07:00
|
|
|
height: 80,
|
2013-04-10 14:03:28 -07:00
|
|
|
tag: item.ImageTags.Thumb
|
|
|
|
});
|
|
|
|
|
2014-01-02 21:58:22 -07:00
|
|
|
}
|
2014-03-17 18:45:28 -07:00
|
|
|
else if (item.Type == "TvChannel" || item.Type == "Recording") {
|
2014-01-02 21:58:22 -07:00
|
|
|
url = "css/images/items/detail/tv.png";
|
|
|
|
}
|
|
|
|
else if (item.MediaType == "Audio") {
|
|
|
|
url = "css/images/items/detail/audio.png";
|
|
|
|
}
|
|
|
|
else {
|
2013-04-10 14:03:28 -07:00
|
|
|
url = "css/images/items/detail/video.png";
|
|
|
|
}
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
var name = item.Name;
|
|
|
|
var seriesName = '';
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2014-01-02 21:58:22 -07:00
|
|
|
// Channel number
|
|
|
|
if (item.Number) {
|
|
|
|
name = item.Number + ' ' + name;
|
|
|
|
}
|
2013-04-10 14:03:28 -07:00
|
|
|
if (item.IndexNumber != null) {
|
|
|
|
name = item.IndexNumber + " - " + name;
|
|
|
|
}
|
|
|
|
if (item.ParentIndexNumber != null) {
|
|
|
|
name = item.ParentIndexNumber + "." + name;
|
|
|
|
}
|
|
|
|
if (item.SeriesName || item.Album || item.ProductionYear) {
|
|
|
|
seriesName = item.SeriesName || item.Album || item.ProductionYear;
|
|
|
|
}
|
2014-01-02 21:58:22 -07:00
|
|
|
if (item.CurrentProgram) {
|
|
|
|
seriesName = item.CurrentProgram.Name;
|
|
|
|
}
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2014-01-02 21:58:22 -07:00
|
|
|
var href = LibraryBrowser.getHref(item.CurrentProgram || item);
|
2013-05-27 18:59:26 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
var nowPlayingText = (name ? name + "\n" : "") + (seriesName || "---");
|
2014-01-02 21:58:22 -07:00
|
|
|
if (item.SeriesName || item.Album || item.CurrentProgram) {
|
2014-03-14 14:25:25 -07:00
|
|
|
nowPlayingText = (seriesName ? seriesName : "") + "\n" + (name || "---");
|
2013-05-27 18:59:26 -07:00
|
|
|
}
|
2013-03-27 19:01:26 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
// Fix for apostrophes and quotes
|
|
|
|
var htmlTitle = trimTitle(nowPlayingText).replace(/'/g, ''').replace(/"/g, '"');
|
|
|
|
html += "<div><a href='" + href + "'><img class='nowPlayingBarImage' alt='" + htmlTitle +
|
|
|
|
"' title='" + htmlTitle + "' src='" + url + "' style='height:40px;display:inline-block;' /></a></div>";
|
|
|
|
html += "<div class='nowPlayingText' title='" + htmlTitle + "'>" + titleHtml(nowPlayingText) + "</div>";
|
|
|
|
|
2014-03-20 01:34:54 -07:00
|
|
|
$('.nowPlayingMediaInfo', mediaControls).html(html);
|
2013-04-10 14:03:28 -07:00
|
|
|
};
|
2013-03-27 19:01:26 -07:00
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
self.getItemsForPlayback = function (query) {
|
|
|
|
|
|
|
|
var userId = Dashboard.getCurrentUserId();
|
|
|
|
|
|
|
|
query.Limit = query.Limit || 100;
|
2013-08-09 08:55:22 -07:00
|
|
|
query.Fields = getItemFields;
|
2013-06-07 09:06:32 -07:00
|
|
|
|
|
|
|
return ApiClient.getItems(userId, query);
|
|
|
|
};
|
|
|
|
|
2014-01-14 13:03:35 -07:00
|
|
|
self.playById = function (id, startPositionTicks) {
|
2013-04-30 10:21:21 -07:00
|
|
|
|
|
|
|
ApiClient.getItem(Dashboard.getCurrentUserId(), id).done(function (item) {
|
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
if (item.IsFolder) {
|
2013-04-30 10:21:21 -07:00
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
self.getItemsForPlayback({
|
2013-04-30 10:21:21 -07:00
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
ParentId: id,
|
|
|
|
Recursive: true,
|
|
|
|
SortBy: "SortName"
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
|
|
|
self.play(result.Items, startPositionTicks);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
self.play([item], startPositionTicks);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2013-04-30 10:21:21 -07:00
|
|
|
|
2013-05-23 13:09:01 -07:00
|
|
|
};
|
2013-05-03 21:02:46 -07:00
|
|
|
|
2013-08-09 08:55:22 -07:00
|
|
|
self.playInstantMixFromSong = function (id) {
|
|
|
|
|
|
|
|
ApiClient.getInstantMixFromSong(id, {
|
|
|
|
|
|
|
|
UserId: Dashboard.getCurrentUserId(),
|
|
|
|
Fields: getItemFields,
|
|
|
|
Limit: 50
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
|
|
|
self.play(result.Items);
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
self.playInstantMixFromAlbum = function (id) {
|
|
|
|
|
|
|
|
ApiClient.getInstantMixFromAlbum(id, {
|
|
|
|
|
|
|
|
UserId: Dashboard.getCurrentUserId(),
|
|
|
|
Fields: getItemFields,
|
|
|
|
Limit: 50
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
|
|
|
self.play(result.Items);
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
self.playInstantMixFromArtist = function (name) {
|
|
|
|
|
|
|
|
ApiClient.getInstantMixFromArtist(name, {
|
|
|
|
|
|
|
|
UserId: Dashboard.getCurrentUserId(),
|
|
|
|
Fields: getItemFields,
|
|
|
|
Limit: 50
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
|
|
|
self.play(result.Items);
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
self.playInstantMixFromMusicGenre = function (name) {
|
|
|
|
|
|
|
|
ApiClient.getInstantMixFromMusicGenre(name, {
|
|
|
|
|
|
|
|
UserId: Dashboard.getCurrentUserId(),
|
|
|
|
Fields: getItemFields,
|
|
|
|
Limit: 50
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
|
|
|
self.play(result.Items);
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-08-08 07:53:25 -07:00
|
|
|
self.playArtist = function (artist) {
|
|
|
|
|
|
|
|
self.getItemsForPlayback({
|
|
|
|
|
|
|
|
Artists: artist,
|
|
|
|
Recursive: true,
|
|
|
|
SortBy: "Album,SortName",
|
|
|
|
IncludeItemTypes: "Audio"
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
|
|
|
self.play(result.Items);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-09-03 08:52:46 -07:00
|
|
|
self.shuffleArtist = function (artist) {
|
|
|
|
|
|
|
|
self.getItemsForPlayback({
|
|
|
|
|
|
|
|
Artists: artist,
|
|
|
|
Recursive: true,
|
|
|
|
SortBy: "Random",
|
|
|
|
IncludeItemTypes: "Audio"
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
|
|
|
self.play(result.Items);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
self.shuffleMusicGenre = function (genre) {
|
|
|
|
|
|
|
|
self.getItemsForPlayback({
|
|
|
|
|
|
|
|
Genres: genre,
|
|
|
|
Recursive: true,
|
|
|
|
SortBy: "Random",
|
|
|
|
IncludeItemTypes: "Audio"
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
|
|
|
self.play(result.Items);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
self.shuffleFolder = function (id) {
|
|
|
|
|
|
|
|
self.getItemsForPlayback({
|
|
|
|
|
|
|
|
ParentId: id,
|
|
|
|
Recursive: true,
|
|
|
|
SortBy: "Random"
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
|
|
|
self.play(result.Items);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
self.removeFromPlaylist = function (index) {
|
2013-06-07 10:23:23 -07:00
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
self.playlist.remove(index);
|
2013-06-07 10:23:23 -07:00
|
|
|
|
2013-05-23 13:09:01 -07:00
|
|
|
};
|
2013-05-03 21:02:46 -07:00
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
// Gets or sets the current playlist index
|
2013-06-07 10:23:23 -07:00
|
|
|
self.currentPlaylistIndex = function (i) {
|
2013-05-03 21:02:46 -07:00
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
if (i == null) {
|
|
|
|
return currentPlaylistIndex;
|
|
|
|
}
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
var newItem = self.playlist[i];
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
Dashboard.getCurrentUser().done(function (user) {
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
self.playInternal(newItem, 0, user);
|
2013-06-07 10:23:23 -07:00
|
|
|
currentPlaylistIndex = i;
|
2013-06-07 09:06:32 -07:00
|
|
|
});
|
2013-04-30 10:21:21 -07:00
|
|
|
};
|
|
|
|
|
2013-07-18 20:12:52 -07:00
|
|
|
self.nextTrack = function () {
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
var newIndex = currentPlaylistIndex + 1;
|
|
|
|
var newItem = self.playlist[newIndex];
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2013-07-16 14:55:50 -07:00
|
|
|
if (newItem) {
|
|
|
|
Dashboard.getCurrentUser().done(function (user) {
|
2013-06-07 09:06:32 -07:00
|
|
|
|
2013-07-16 14:55:50 -07:00
|
|
|
self.playInternal(newItem, 0, user);
|
|
|
|
currentPlaylistIndex = newIndex;
|
|
|
|
});
|
|
|
|
}
|
2013-05-23 13:09:01 -07:00
|
|
|
};
|
2013-08-09 08:55:22 -07:00
|
|
|
|
2013-07-18 20:12:52 -07:00
|
|
|
self.previousTrack = function () {
|
|
|
|
var newIndex = currentPlaylistIndex - 1;
|
|
|
|
if (newIndex >= 0) {
|
|
|
|
var newItem = self.playlist[newIndex];
|
|
|
|
|
|
|
|
if (newItem) {
|
|
|
|
Dashboard.getCurrentUser().done(function (user) {
|
|
|
|
|
|
|
|
self.playInternal(newItem, 0, user);
|
|
|
|
currentPlaylistIndex = newIndex;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2013-05-03 21:02:46 -07:00
|
|
|
|
2013-11-30 11:32:39 -07:00
|
|
|
self.queueItemsNext = function (items) {
|
|
|
|
|
|
|
|
var insertIndex = 1;
|
|
|
|
|
|
|
|
for (var i = 0, length = items.length; i < length; i++) {
|
|
|
|
|
|
|
|
self.playlist.splice(insertIndex, 0, items[i]);
|
|
|
|
|
|
|
|
insertIndex++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-29 23:07:45 -07:00
|
|
|
self.queueItems = function (items) {
|
2013-06-07 09:06:32 -07:00
|
|
|
|
2013-11-29 23:07:45 -07:00
|
|
|
for (var i = 0, length = items.length; i < length; i++) {
|
2013-06-07 09:06:32 -07:00
|
|
|
|
2013-11-29 23:07:45 -07:00
|
|
|
self.playlist.push(items[i]);
|
|
|
|
}
|
2013-04-30 10:21:21 -07:00
|
|
|
};
|
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
self.queue = function (id) {
|
|
|
|
|
2014-01-18 10:58:05 -07:00
|
|
|
if (!currentMediaElement) {
|
|
|
|
self.playById(id);
|
|
|
|
return;
|
|
|
|
}
|
2014-01-29 14:54:40 -07:00
|
|
|
|
2013-06-07 09:06:32 -07:00
|
|
|
ApiClient.getItem(Dashboard.getCurrentUserId(), id).done(function (item) {
|
|
|
|
|
|
|
|
if (item.IsFolder) {
|
|
|
|
|
|
|
|
self.getItemsForPlayback({
|
|
|
|
|
|
|
|
ParentId: id,
|
|
|
|
Recursive: true,
|
|
|
|
SortBy: "SortName"
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
2013-11-29 23:07:45 -07:00
|
|
|
self.queueItems(result.Items);
|
2013-06-07 09:06:32 -07:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
2013-11-29 23:07:45 -07:00
|
|
|
self.queueItems([item]);
|
2013-06-07 09:06:32 -07:00
|
|
|
}
|
|
|
|
|
2013-05-23 13:09:01 -07:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-08-08 07:53:25 -07:00
|
|
|
self.queueArtist = function (artist) {
|
|
|
|
|
|
|
|
self.getItemsForPlayback({
|
|
|
|
|
|
|
|
Artists: artist,
|
|
|
|
Recursive: true,
|
|
|
|
SortBy: "Album,SortName",
|
|
|
|
IncludeItemTypes: "Audio"
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
2013-11-29 23:07:45 -07:00
|
|
|
self.queueItems(result.Items);
|
2013-08-08 07:53:25 -07:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-05-23 13:09:01 -07:00
|
|
|
self.pause = function () {
|
|
|
|
currentMediaElement.pause();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.unpause = function () {
|
|
|
|
currentMediaElement.play();
|
|
|
|
};
|
|
|
|
|
2013-07-17 20:18:16 -07:00
|
|
|
self.seek = function (position) {
|
2013-07-25 12:43:40 -07:00
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.changeStream(position);
|
2013-07-25 12:43:40 -07:00
|
|
|
|
2013-07-17 20:18:16 -07:00
|
|
|
};
|
2013-08-09 08:55:22 -07:00
|
|
|
|
2013-05-23 13:09:01 -07:00
|
|
|
self.mute = function () {
|
2013-08-27 21:31:34 -07:00
|
|
|
|
|
|
|
if (currentMediaElement) {
|
|
|
|
currentMediaElement.volume = 0;
|
2014-03-08 01:09:45 -07:00
|
|
|
currentMediaElement.muted = true;
|
|
|
|
self.volumeSlider.val(0).slider('refresh');
|
2013-08-27 21:31:34 -07:00
|
|
|
}
|
2013-05-23 13:09:01 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
self.unmute = function () {
|
2014-03-08 01:09:45 -07:00
|
|
|
|
2013-08-27 21:31:34 -07:00
|
|
|
if (currentMediaElement) {
|
2014-03-08 01:09:45 -07:00
|
|
|
var volume = localStorage.getItem("volume") || self.volumeSlider.val();
|
|
|
|
currentMediaElement.volume = volume;
|
|
|
|
currentMediaElement.muted = false;
|
|
|
|
self.volumeSlider.val(volume).slider('refresh');
|
2013-08-27 21:31:34 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.toggleMute = function () {
|
|
|
|
|
|
|
|
if (currentMediaElement) {
|
2014-03-08 01:09:45 -07:00
|
|
|
var volume = localStorage.getItem("volume") || self.volumeSlider.val();
|
|
|
|
currentMediaElement.volume = currentMediaElement.volume ? 0 : volume;
|
|
|
|
currentMediaElement.muted = currentMediaElement.volume == 0;
|
|
|
|
self.volumeSlider.val(volume).slider('refresh');
|
2013-08-27 21:31:34 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-27 22:44:43 -07:00
|
|
|
self.volumeDown = function () {
|
2013-08-27 21:31:34 -07:00
|
|
|
|
|
|
|
if (currentMediaElement) {
|
2013-08-28 07:01:04 -07:00
|
|
|
currentMediaElement.volume = Math.max(currentMediaElement.volume - .02, 0);
|
2014-03-08 01:09:45 -07:00
|
|
|
localStorage.setItem("volume", currentMediaElement.volume);
|
|
|
|
self.volumeSlider.val(currentMediaElement.volume).slider('refresh');
|
2013-08-27 21:31:34 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-27 22:44:43 -07:00
|
|
|
self.volumeUp = function () {
|
2013-08-27 21:31:34 -07:00
|
|
|
|
|
|
|
if (currentMediaElement) {
|
2013-08-28 07:01:04 -07:00
|
|
|
currentMediaElement.volume = Math.min(currentMediaElement.volume + .02, 1);
|
2014-03-08 01:09:45 -07:00
|
|
|
localStorage.setItem("volume", currentMediaElement.volume);
|
|
|
|
self.volumeSlider.val(currentMediaElement.volume).slider('refresh');
|
2013-08-27 21:31:34 -07:00
|
|
|
}
|
2013-04-30 10:21:21 -07:00
|
|
|
};
|
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
self.stop = function () {
|
2013-03-31 18:52:07 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
var elem = currentMediaElement;
|
2013-03-31 18:52:07 -07:00
|
|
|
|
2013-05-23 20:33:33 -07:00
|
|
|
elem.pause();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
2014-03-17 15:37:05 -07:00
|
|
|
$(elem).off("ended.playnext").on("ended", function () {
|
2013-06-07 10:23:23 -07:00
|
|
|
|
|
|
|
$(this).remove();
|
|
|
|
elem.src = "";
|
|
|
|
currentMediaElement = null;
|
2013-03-26 14:32:01 -07:00
|
|
|
|
2014-03-17 15:37:05 -07:00
|
|
|
}).trigger("ended");
|
2013-02-27 10:53:42 -07:00
|
|
|
|
2014-03-14 14:16:01 -07:00
|
|
|
if (currentItem.MediaType == "Video") {
|
2014-03-08 01:09:45 -07:00
|
|
|
if (self.isFullScreen()) {
|
|
|
|
self.exitFullScreen();
|
|
|
|
}
|
2014-03-14 14:16:01 -07:00
|
|
|
self.resetEnhancements();
|
2014-03-17 15:37:05 -07:00
|
|
|
} else {
|
2014-03-20 01:34:54 -07:00
|
|
|
$('#nowPlayingBar').hide();
|
2013-12-29 19:41:22 -07:00
|
|
|
}
|
2013-04-10 14:03:28 -07:00
|
|
|
};
|
2013-03-26 14:32:01 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
self.isPlaying = function () {
|
|
|
|
return currentMediaElement;
|
|
|
|
};
|
2013-05-25 17:53:51 -07:00
|
|
|
|
2014-01-03 21:53:49 -07:00
|
|
|
self.showSendMediaMenu = function () {
|
|
|
|
|
|
|
|
RemoteControl.showMenuForItem({
|
|
|
|
item: currentItem
|
|
|
|
});
|
2014-01-08 13:29:09 -07:00
|
|
|
|
2014-01-03 21:53:49 -07:00
|
|
|
};
|
2014-03-20 01:34:54 -07:00
|
|
|
|
|
|
|
self.bindPositionSlider = function () {
|
|
|
|
self.positionSlider.on('slidestart', function (e) {
|
|
|
|
|
|
|
|
self.isPositionSliderActive = true;
|
|
|
|
|
|
|
|
}).on('slidestop', onPositionSliderChange);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.bindVolumeSlider = function () {
|
|
|
|
self.volumeSlider.on('slidestop', function () {
|
|
|
|
|
|
|
|
var vol = this.value;
|
|
|
|
|
|
|
|
self.updateVolumeButtons(vol);
|
|
|
|
currentMediaElement.volume = vol;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$(window).on("beforeunload popstate", function () {
|
|
|
|
|
|
|
|
var item = currentItem;
|
|
|
|
var media = currentMediaElement;
|
|
|
|
|
|
|
|
// Try to report playback stopped before the browser closes
|
|
|
|
if (item && media && currentProgressInterval) {
|
|
|
|
|
|
|
|
var endTime = currentMediaElement.currentTime;
|
|
|
|
|
|
|
|
var position = Math.floor(10000000 * endTime) + self.startTimeTicksOffset;
|
|
|
|
|
|
|
|
ApiClient.reportPlaybackStopped(Dashboard.getCurrentUserId(), currentItem.Id, position);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
initPlayer();
|
|
|
|
});
|
|
|
|
|
|
|
|
function initPlayer() {
|
|
|
|
self.muteButton = $('.muteButton');
|
|
|
|
self.unmuteButton = $('.unmuteButton');
|
|
|
|
self.currentTimeElement = $('.currentTime');
|
|
|
|
self.volumeSlider = $('.volumeSlider');
|
|
|
|
self.positionSlider = $(".positionSlider");
|
|
|
|
|
|
|
|
self.bindVolumeSlider();
|
|
|
|
self.bindPositionSlider();
|
|
|
|
};
|
|
|
|
|
|
|
|
function replaceQueryString(url, param, value) {
|
|
|
|
var re = new RegExp("([?|&])" + param + "=.*?(&|$)", "i");
|
|
|
|
if (url.match(re))
|
|
|
|
return url.replace(re, '$1' + param + "=" + value + '$2');
|
|
|
|
else
|
|
|
|
return url + '&' + param + "=" + value;
|
|
|
|
};
|
|
|
|
|
|
|
|
function sendProgressUpdate(itemId) {
|
|
|
|
|
|
|
|
ApiClient.reportPlaybackProgress(Dashboard.getCurrentUserId(), itemId, self.getCurrentTicks(), currentMediaElement.paused, currentMediaElement.volume == 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
function clearProgressInterval() {
|
|
|
|
|
|
|
|
if (currentProgressInterval) {
|
|
|
|
clearTimeout(currentProgressInterval);
|
|
|
|
currentProgressInterval = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function canPlayWebm() {
|
|
|
|
|
|
|
|
return testableVideoElement.canPlayType('video/webm').replace(/no/, '');
|
|
|
|
};
|
|
|
|
|
|
|
|
function onPositionSliderChange() {
|
|
|
|
|
|
|
|
self.isPositionSliderActive = false;
|
|
|
|
|
|
|
|
var newPercent = parseInt(this.value);
|
|
|
|
|
|
|
|
var newPositionTicks = (newPercent / 100) * currentItem.RunTimeTicks;
|
|
|
|
|
|
|
|
self.changeStream(Math.floor(newPositionTicks));
|
|
|
|
};
|
|
|
|
|
|
|
|
function endsWith(text, pattern) {
|
|
|
|
|
|
|
|
text = text.toLowerCase();
|
|
|
|
pattern = pattern.toLowerCase();
|
|
|
|
|
|
|
|
var d = text.length - pattern.length;
|
|
|
|
return d >= 0 && text.lastIndexOf(pattern) === d;
|
|
|
|
};
|
|
|
|
|
|
|
|
function playAudio(item, startPositionTicks) {
|
|
|
|
|
|
|
|
startPositionTicks = startPositionTicks || 0;
|
|
|
|
|
|
|
|
var baseParams = {
|
|
|
|
audioChannels: 2,
|
|
|
|
audioBitrate: 128000,
|
|
|
|
StartTimeTicks: startPositionTicks
|
|
|
|
};
|
|
|
|
|
|
|
|
var mp3Url = ApiClient.getUrl('Audio/' + item.Id + '/stream.mp3', $.extend({}, baseParams, {
|
|
|
|
audioCodec: 'mp3'
|
|
|
|
}));
|
|
|
|
|
|
|
|
var aacUrl = ApiClient.getUrl('Audio/' + item.Id + '/stream.aac', $.extend({}, baseParams, {
|
|
|
|
audioCodec: 'aac'
|
|
|
|
}));
|
|
|
|
|
|
|
|
var webmUrl = ApiClient.getUrl('Audio/' + item.Id + '/stream.webm', $.extend({}, baseParams, {
|
|
|
|
audioCodec: 'Vorbis'
|
|
|
|
}));
|
|
|
|
|
|
|
|
var mediaStreams = item.MediaStreams || [];
|
|
|
|
|
|
|
|
var isStatic = false;
|
|
|
|
var seekParam = isStatic && startPositionTicks ? '#t=' + (startPositionTicks / 10000000) : '';
|
|
|
|
|
|
|
|
for (var i = 0, length = mediaStreams.length; i < length; i++) {
|
|
|
|
|
|
|
|
var stream = mediaStreams[i];
|
|
|
|
|
|
|
|
if (stream.Type == "Audio") {
|
|
|
|
|
|
|
|
// Stream statically when possible
|
|
|
|
if (endsWith(item.Path, ".aac") && stream.BitRate <= 256000) {
|
|
|
|
aacUrl += "&static=true" + seekParam;
|
|
|
|
isStatic = true;
|
|
|
|
}
|
|
|
|
else if (endsWith(item.Path, ".mp3") && stream.BitRate <= 256000) {
|
|
|
|
mp3Url += "&static=true" + seekParam;
|
|
|
|
isStatic = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.startTimeTicksOffset = isStatic ? 0 : startPositionTicks;
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
var requiresControls = $.browser.android || ($.browser.webkit && !$.browser.chrome);
|
|
|
|
|
|
|
|
// Can't autoplay in these browsers so we need to use the full controls
|
|
|
|
if (requiresControls) {
|
|
|
|
html += '<audio preload="auto" autoplay controls>';
|
|
|
|
} else {
|
|
|
|
html += '<audio preload="auto" style="display:none;" autoplay>';
|
|
|
|
}
|
|
|
|
html += '<source type="audio/mpeg" src="' + mp3Url + '" />';
|
|
|
|
html += '<source type="audio/aac" src="' + aacUrl + '" />';
|
|
|
|
html += '<source type="audio/webm" src="' + webmUrl + '" />';
|
|
|
|
html += '</audio>';
|
|
|
|
|
|
|
|
var nowPlayingBar = $('#nowPlayingBar').show();
|
|
|
|
//show stop button
|
|
|
|
$('#stopButton', nowPlayingBar).show();
|
|
|
|
$('#playButton', nowPlayingBar).hide();
|
|
|
|
$('#pauseButton', nowPlayingBar).show();
|
|
|
|
$('#fullscreenButton', nowPlayingBar).hide();
|
|
|
|
|
|
|
|
$('#previousTrackButton', nowPlayingBar).show();
|
|
|
|
$('#nextTrackButton', nowPlayingBar).show();
|
|
|
|
$('#playlistButton', nowPlayingBar).show();
|
|
|
|
|
|
|
|
$('#qualityButton', nowPlayingBar).hide();
|
|
|
|
$('#audioTracksButton', nowPlayingBar).hide();
|
|
|
|
$('#subtitleButton', nowPlayingBar).hide();
|
|
|
|
$('#chaptersButton', nowPlayingBar).hide();
|
|
|
|
|
|
|
|
$('#mediaElement', nowPlayingBar).html(html);
|
|
|
|
var audioElement = $("audio", mediaElement);
|
|
|
|
|
|
|
|
var initialVolume = localStorage.getItem("volume") || 0.5;
|
|
|
|
|
|
|
|
audioElement.each(function () {
|
|
|
|
this.volume = initialVolume;
|
|
|
|
});
|
|
|
|
|
|
|
|
self.volumeSlider.val(initialVolume).slider('refresh');
|
|
|
|
self.updateVolumeButtons(initialVolume);
|
|
|
|
|
|
|
|
audioElement.on("volumechange", function () {
|
|
|
|
|
|
|
|
var vol = this.volume;
|
|
|
|
|
|
|
|
localStorage.setItem("volume", vol);
|
|
|
|
|
|
|
|
self.updateVolumeButtons(vol);
|
|
|
|
|
|
|
|
}).on("play.once", function () {
|
|
|
|
|
|
|
|
if (!requiresControls) {
|
|
|
|
audioElement.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
self.updateCanClientSeek(this);
|
|
|
|
|
|
|
|
audioElement.off("play.once");
|
|
|
|
|
|
|
|
ApiClient.reportPlaybackStart(Dashboard.getCurrentUserId(), item.Id, true, item.MediaType);
|
|
|
|
|
|
|
|
self.startProgressInterval(item.Id);
|
|
|
|
|
|
|
|
}).on("pause", function () {
|
|
|
|
|
|
|
|
$('#playButton', nowPlayingBar).show();
|
|
|
|
$('#pauseButton', nowPlayingBar).hide();
|
|
|
|
|
|
|
|
}).on("playing", function () {
|
|
|
|
|
|
|
|
$('#playButton', nowPlayingBar).hide();
|
|
|
|
$('#pauseButton', nowPlayingBar).show();
|
|
|
|
|
|
|
|
}).on("timeupdate", function () {
|
|
|
|
|
|
|
|
if (!self.isPositionSliderActive) {
|
|
|
|
|
|
|
|
self.setCurrentTime(self.getCurrentTicks(this), item, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}).on("ended.playbackstopped", self.onPlaybackStopped).on('ended.playnext', self.playNextAfterEnded);
|
|
|
|
|
|
|
|
currentItem = item;
|
|
|
|
curentDurationTicks = item.RunTimeTicks;
|
|
|
|
|
|
|
|
return audioElement[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
function canPlayAudioStreamDirect(audioStream) {
|
|
|
|
|
|
|
|
var audioCodec = (audioStream.Codec || '').toLowerCase().replace('-', '');
|
|
|
|
|
|
|
|
if (audioCodec.indexOf('aac') == -1 &&
|
|
|
|
audioCodec.indexOf('mp3') == -1 &&
|
|
|
|
audioCodec.indexOf('mpeg') == -1) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (audioStream.Channels == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// IE won't play at all if more than two channels
|
|
|
|
if (audioStream.Channels > 2 && $.browser.msie) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
function trunc(string, len) {
|
|
|
|
if (string.length > 0 && string.length < len) return string;
|
|
|
|
var trimmed = $.trim(string).substring(0, len).split(" ").slice(0, -1).join(" ");
|
|
|
|
if (trimmed) {
|
|
|
|
trimmed += "...";
|
|
|
|
} else {
|
|
|
|
trimmed = "---"
|
|
|
|
}
|
|
|
|
return trimmed;
|
|
|
|
};
|
|
|
|
|
|
|
|
function trimTitle(title) {
|
|
|
|
return title.replace("\n---", "");
|
|
|
|
};
|
|
|
|
|
|
|
|
function titleHtml(title) {
|
|
|
|
var titles = title.split("\n");
|
|
|
|
return (trunc(titles[0], 30) + "<br />" + trunc(titles[1], 30)).replace("---", " ");
|
|
|
|
};
|
|
|
|
|
|
|
|
var getItemFields = "MediaStreams,Chapters,Path";
|
2013-04-10 14:03:28 -07:00
|
|
|
}
|
2013-03-26 14:32:01 -07:00
|
|
|
|
2013-04-10 14:03:28 -07:00
|
|
|
window.MediaPlayer = new mediaPlayer();
|
2013-04-08 21:26:02 -07:00
|
|
|
|
2013-05-23 20:33:33 -07:00
|
|
|
})(document, setTimeout, clearTimeout, screen, localStorage, $, setInterval, window);
|