jellyfin-web/dashboard-ui/scripts/mediaplayer.js

1970 lines
59 KiB
JavaScript
Raw Normal View History

2014-07-15 12:16:16 -07:00
(function (document, setTimeout, clearTimeout, screen, store, $, 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 currentProgressInterval;
2014-01-10 06:52:01 -07:00
var canClientSeek;
var currentPlaylistIndex = 0;
2013-05-23 13:09:01 -07:00
2015-06-07 13:06:18 -07:00
self.currentMediaRenderer = null;
2014-06-11 12:31:33 -07:00
self.currentItem = null;
self.currentMediaSource = null;
2014-03-31 14:43:49 -07:00
self.currentDurationTicks = null;
2014-03-29 08:40:32 -07:00
self.startTimeTicksOffset = null;
2013-06-07 09:06:32 -07:00
self.playlist = [];
2014-03-29 08:40:32 -07:00
self.isLocalPlayer = true;
2014-04-06 10:53:23 -07:00
self.isDefaultPlayer = true;
2014-07-01 14:13:32 -07:00
2014-03-29 09:58:49 -07:00
self.name = 'Html5 Player';
self.getTargets = function () {
var targets = [{
2015-05-06 20:11:51 -07:00
name: Globalize.translate('MyDevice'),
2014-10-25 11:32:58 -07:00
id: ConnectionManager.deviceId(),
2014-03-29 11:20:42 -07:00
playerName: self.name,
playableMediaTypes: ['Audio', 'Video'],
2014-04-13 10:27:13 -07:00
isLocalPlayer: true,
supportedCommands: Dashboard.getSupportedRemoteCommands()
2014-03-29 09:58:49 -07:00
}];
return targets;
};
2014-03-29 08:40:32 -07:00
2015-05-24 11:33:28 -07:00
var canPlayAac = document.createElement('audio').canPlayType('audio/aac').replace(/no/, '');
self.getVideoQualityOptions = function (videoWidth) {
var bitrateSetting = AppSettings.maxStreamingBitrate();
var maxAllowedWidth = videoWidth || 4096;
var options = [];
// Some 1080- videos are reported as 1912?
if (maxAllowedWidth >= 1900) {
options.push({ name: '1080p - 30Mbps', maxWidth: 1920, bitrate: 30000000 });
options.push({ name: '1080p - 25Mbps', maxWidth: 1920, bitrate: 25000000 });
options.push({ name: '1080p - 20Mbps', maxWidth: 1920, bitrate: 20000000 });
options.push({ name: '1080p - 15Mbps', maxWidth: 1920, bitrate: 15000000 });
options.push({ name: '1080p - 10Mbps', maxWidth: 1920, bitrate: 10000000 });
options.push({ name: '1080p - 8Mbps', maxWidth: 1920, bitrate: 8000000 });
options.push({ name: '1080p - 6Mbps', maxWidth: 1920, bitrate: 6000000 });
options.push({ name: '1080p - 5Mbps', maxWidth: 1920, bitrate: 5000000 });
} else if (maxAllowedWidth >= 1260) {
options.push({ name: '720p - 10Mbps', maxWidth: 1280, bitrate: 10000000 });
options.push({ name: '720p - 8Mbps', maxWidth: 1280, bitrate: 8000000 });
options.push({ name: '720p - 6Mbps', maxWidth: 1280, bitrate: 6000000 });
options.push({ name: '720p - 5Mbps', maxWidth: 1280, bitrate: 5000000 });
} else if (maxAllowedWidth >= 460) {
options.push({ name: '480p - 4Mbps', maxWidth: 720, bitrate: 4000000 });
options.push({ name: '480p - 3Mbps', maxWidth: 720, bitrate: 3000000 });
options.push({ name: '480p - 2.5Mbps', maxWidth: 720, bitrate: 2500000 });
options.push({ name: '480p - 2Mbps', maxWidth: 720, bitrate: 2000000 });
options.push({ name: '480p - 1.5Mbps', maxWidth: 720, bitrate: 1500000 });
}
if (maxAllowedWidth >= 1260) {
options.push({ name: '720p - 4Mbps', maxWidth: 1280, bitrate: 4000000 });
options.push({ name: '720p - 3Mbps', maxWidth: 1280, bitrate: 3000000 });
options.push({ name: '720p - 2Mbps', maxWidth: 1280, bitrate: 2000000 });
// The extra 1 is because they're keyed off the bitrate value
2015-04-10 19:43:30 -07:00
options.push({ name: '720p - 1.5Mbps', maxWidth: 1280, bitrate: 1500001 });
options.push({ name: '720p - 1Mbps', maxWidth: 1280, bitrate: 1000001 });
}
options.push({ name: '480p - 1.0Mbps', maxWidth: 720, bitrate: 1000000 });
options.push({ name: '480p - 720kbps', maxWidth: 720, bitrate: 720000 });
options.push({ name: '480p - 420kbps', maxWidth: 720, bitrate: 420000 });
options.push({ name: '360p', maxWidth: 640, bitrate: 400000 });
options.push({ name: '240p', maxWidth: 426, bitrate: 320000 });
2015-03-29 20:04:55 -07:00
options.push({ name: '144p', maxWidth: 256, bitrate: 192000 });
var i, length, option;
var selectedIndex = -1;
for (i = 0, length = options.length; i < length; i++) {
option = options[i];
if (selectedIndex == -1 && option.bitrate <= bitrateSetting) {
selectedIndex = i;
}
}
if (selectedIndex == -1) {
selectedIndex = options.length - 1;
}
options[selectedIndex].selected = true;
return options;
};
2015-05-26 08:31:50 -07:00
self.getDeviceProfile = function (maxWidth) {
2015-05-26 08:31:50 -07:00
if (!maxWidth) {
maxWidth = self.getVideoQualityOptions().filter(function (q) {
return q.selected;
})[0].maxWidth;
}
var bitrateSetting = AppSettings.maxStreamingBitrate();
2015-03-26 12:18:21 -07:00
var canPlayWebm = self.canPlayWebm();
var profile = {};
profile.MaxStreamingBitrate = bitrateSetting;
profile.MaxStaticBitrate = 40000000;
2015-03-26 16:10:34 -07:00
profile.MusicStreamingTranscodingBitrate = Math.min(bitrateSetting, 192000);
profile.DirectPlayProfiles = [];
profile.DirectPlayProfiles.push({
2015-05-02 09:34:27 -07:00
Container: 'mp4,m4v',
Type: 'Video',
VideoCodec: 'h264',
AudioCodec: 'aac,mp3'
});
if ($.browser.chrome) {
profile.DirectPlayProfiles.push({
2015-05-02 09:34:27 -07:00
Container: 'mkv',
Type: 'Video',
VideoCodec: 'h264',
AudioCodec: 'aac,mp3'
});
2015-05-06 20:11:51 -07:00
// TODO: Test this
//profile.DirectPlayProfiles.push({
// Container: 'mov',
// Type: 'Video',
// VideoCodec: 'h264',
// AudioCodec: 'aac,mp3'
//});
}
profile.DirectPlayProfiles.push({
Container: 'mp3',
Type: 'Audio'
});
2015-05-24 11:33:28 -07:00
if (canPlayAac) {
profile.DirectPlayProfiles.push({
Container: 'aac',
Type: 'Audio'
});
}
2015-03-26 12:18:21 -07:00
if (canPlayWebm) {
profile.DirectPlayProfiles.push({
Container: 'webm',
Type: 'Video'
});
profile.DirectPlayProfiles.push({
Container: 'webm,webma',
Type: 'Audio'
});
}
profile.TranscodingProfiles = [];
2015-05-22 12:16:14 -07:00
if (self.canPlayHls()) {
profile.TranscodingProfiles.push({
Container: 'ts',
Type: 'Video',
AudioCodec: 'aac',
VideoCodec: 'h264',
Context: 'Streaming',
Protocol: 'hls'
});
2015-05-24 11:33:28 -07:00
2015-05-25 10:32:22 -07:00
if (canPlayAac && $.browser.safari) {
2015-05-24 11:33:28 -07:00
profile.TranscodingProfiles.push({
2015-06-07 18:23:56 -07:00
Container: 'ts',
2015-05-24 11:33:28 -07:00
Type: 'Audio',
AudioCodec: 'aac',
Context: 'Streaming',
Protocol: 'hls'
});
}
}
2015-03-26 12:18:21 -07:00
if (canPlayWebm) {
profile.TranscodingProfiles.push({
Container: 'webm',
Type: 'Video',
AudioCodec: 'vorbis',
VideoCodec: 'vpx',
Context: 'Streaming',
Protocol: 'http'
});
}
profile.TranscodingProfiles.push({
Container: 'mp4',
Type: 'Video',
AudioCodec: 'aac',
VideoCodec: 'h264',
Context: 'Streaming',
Protocol: 'http'
});
2015-05-31 14:07:44 -07:00
profile.TranscodingProfiles.push({
Container: 'mp4',
Type: 'Video',
AudioCodec: 'aac',
VideoCodec: 'h264',
Context: 'Static',
Protocol: 'http'
});
2015-05-24 11:33:28 -07:00
if (canPlayAac && $.browser.safari) {
profile.TranscodingProfiles.push({
Container: 'aac',
Type: 'Audio',
AudioCodec: 'aac',
Context: 'Streaming',
Protocol: 'http'
});
2015-05-31 14:07:44 -07:00
profile.TranscodingProfiles.push({
Container: 'aac',
Type: 'Audio',
AudioCodec: 'aac',
Context: 'Static',
Protocol: 'http'
});
2015-05-24 11:33:28 -07:00
} else {
profile.TranscodingProfiles.push({
Container: 'mp3',
Type: 'Audio',
AudioCodec: 'mp3',
Context: 'Streaming',
Protocol: 'http'
});
2015-05-31 14:07:44 -07:00
profile.TranscodingProfiles.push({
Container: 'mp3',
Type: 'Audio',
AudioCodec: 'mp3',
Context: 'Static',
Protocol: 'http'
});
2015-05-24 11:33:28 -07:00
}
profile.ContainerProfiles = [];
var audioConditions = [];
2015-04-24 20:30:44 -07:00
2015-04-25 20:25:07 -07:00
var maxAudioChannels = $.browser.msie || $.browser.safari ?
'2' :
'6';
2015-05-19 12:15:40 -07:00
audioConditions.push({
2015-04-25 20:25:07 -07:00
Condition: 'LessThanEqual',
Property: 'AudioChannels',
Value: maxAudioChannels
2015-05-19 12:15:40 -07:00
});
profile.CodecProfiles = [];
profile.CodecProfiles.push({
Type: 'Audio',
Conditions: audioConditions
});
2015-05-19 12:15:40 -07:00
profile.CodecProfiles.push({
Type: 'VideoAudio',
Codec: 'mp3',
Conditions: [{
Condition: 'LessThanEqual',
Property: 'AudioChannels',
Value: maxAudioChannels
}]
});
2015-04-24 20:30:44 -07:00
2015-05-06 20:11:51 -07:00
profile.CodecProfiles.push({
Type: 'VideoAudio',
Codec: 'aac',
Container: 'mkv,mov',
Conditions: [
{
Condition: 'NotEquals',
Property: 'AudioProfile',
Value: 'HE-AAC'
},
{
Condition: 'NotEquals',
Property: 'AudioProfile',
Value: 'LC'
}
]
2015-04-24 20:30:44 -07:00
});
profile.CodecProfiles.push({
Type: 'VideoAudio',
2015-04-24 20:30:44 -07:00
Codec: 'aac',
2015-05-06 20:11:51 -07:00
Conditions: [
2015-05-19 12:15:40 -07:00
{
Condition: 'LessThanEqual',
Property: 'AudioChannels',
Value: maxAudioChannels
}
2015-05-06 20:11:51 -07:00
]
});
profile.CodecProfiles.push({
Type: 'Video',
Codec: 'h264',
Conditions: [
{
Condition: 'NotEquals',
Property: 'IsAnamorphic',
2015-03-26 16:10:34 -07:00
Value: 'true',
IsRequired: false
},
{
Condition: 'EqualsAny',
Property: 'VideoProfile',
Value: 'high|main|baseline|constrained baseline'
},
{
Condition: 'LessThanEqual',
Property: 'VideoLevel',
Value: '41'
},
{
Condition: 'LessThanEqual',
Property: 'Width',
2015-05-26 08:31:50 -07:00
Value: maxWidth
}]
});
profile.CodecProfiles.push({
Type: 'Video',
Codec: 'vpx',
Conditions: [
{
Condition: 'NotEquals',
Property: 'IsAnamorphic',
2015-03-26 16:10:34 -07:00
Value: 'true',
IsRequired: false
},
{
Condition: 'LessThanEqual',
Property: 'Width',
2015-05-26 08:31:50 -07:00
Value: maxWidth
}]
});
// Subtitle profiles
// External vtt or burn in
profile.SubtitleProfiles = [];
if (self.supportsTextTracks()) {
profile.SubtitleProfiles.push({
Format: 'vtt',
Method: 'External'
});
}
2015-05-02 09:34:27 -07:00
profile.ResponseProfiles = [];
profile.ResponseProfiles.push({
Type: 'Video',
Container: 'm4v',
MimeType: 'video/mp4'
});
2015-05-06 20:11:51 -07:00
//profile.ResponseProfiles.push({
// Type: 'Video',
// Container: 'mkv',
// MimeType: 'video/webm'
//});
profile.ResponseProfiles.push({
Type: 'Video',
Container: 'mov',
MimeType: 'video/webm'
});
return profile;
};
2015-06-07 13:06:18 -07:00
self.updateCanClientSeek = function (mediaRenderer) {
2014-10-07 18:37:45 -07:00
2015-06-07 13:06:18 -07:00
var duration = mediaRenderer.duration();
2014-10-03 18:42:38 -07:00
2014-01-10 06:52:01 -07:00
canClientSeek = duration && !isNaN(duration) && duration != Number.POSITIVE_INFINITY && duration != Number.NEGATIVE_INFINITY;
};
2013-05-23 13:09:01 -07:00
2015-06-07 13:06:18 -07:00
self.getCurrentSrc = function (mediaRenderer) {
return mediaRenderer.currentSrc();
2014-10-22 21:26:01 -07:00
};
2015-06-07 13:06:18 -07:00
self.getCurrentTicks = function (mediaRenderer) {
2014-06-13 07:24:14 -07:00
2015-06-07 13:06:18 -07:00
var playerTime = Math.floor(10000000 * (mediaRenderer || self.currentMediaRenderer).currentTime());
2014-06-13 07:24:14 -07:00
2014-07-01 14:13:32 -07:00
playerTime += self.startTimeTicksOffset;
2014-06-13 07:24:14 -07:00
return playerTime;
};
2013-05-25 21:52:14 -07:00
self.playNextAfterEnded = function () {
2013-06-07 10:23:23 -07:00
self.nextTrack();
};
2013-05-23 13:09:01 -07:00
2014-05-07 11:38:50 -07:00
self.startProgressInterval = function () {
2013-05-23 13:09:01 -07:00
clearProgressInterval();
2014-11-13 23:27:10 -07:00
var intervalTime = ApiClient.isWebSocketOpen() ? 1200 : 5000;
self.lastProgressReport = 0;
2013-05-23 13:09:01 -07:00
currentProgressInterval = setInterval(function () {
2015-06-07 13:06:18 -07:00
if (self.currentMediaRenderer) {
2014-11-13 23:27:10 -07:00
if ((new Date().getTime() - self.lastProgressReport) > intervalTime) {
self.lastProgressReport = new Date().getTime();
sendProgressUpdate();
}
2013-05-23 15:39:51 -07:00
}
2013-04-08 21:26:02 -07:00
2014-11-13 23:27:10 -07:00
}, 250);
};
2014-01-10 06:52:01 -07:00
2014-10-07 18:37:45 -07:00
self.getCurrentMediaExtension = function (currentSrc) {
2014-10-03 18:42:38 -07:00
currentSrc = currentSrc.split('?')[0];
return currentSrc.substring(currentSrc.lastIndexOf('.'));
};
2015-06-01 22:46:06 -07:00
self.canPlayNativeHls = function () {
2015-06-07 18:23:56 -07:00
// Don't use HLS on android 4.4, regardless of what the browser reports
if ($.browser.android) {
var agent = navigator.userAgent.toLowerCase();
if (agent.indexOf('android 4.4') != -1) {
return false;
}
}
2015-06-07 13:06:18 -07:00
var media = document.createElement('video');
// safari
if (media.canPlayType('application/x-mpegURL').replace(/no/, '') ||
media.canPlayType('application/vnd.apple.mpegURL').replace(/no/, '')) {
return true;
}
return false;
};
2015-06-01 22:46:06 -07:00
self.canPlayHls = function () {
if (self.canPlayNativeHls()) {
return true;
}
//return $.browser.chrome || $.browser.msie;
return false;
};
self.changeStream = function (ticks, params) {
2013-05-23 18:47:07 -07:00
2015-06-07 13:06:18 -07:00
var mediaRenderer = self.currentMediaRenderer;
2013-05-23 18:47:07 -07:00
2014-01-10 06:52:01 -07:00
if (canClientSeek && params == null) {
2013-05-23 18:47:07 -07:00
2015-06-07 13:06:18 -07:00
mediaRenderer.currentTime(ticks / (1000 * 10000));
return;
}
2013-05-23 18:47:07 -07:00
params = params || {};
2013-05-23 18:47:07 -07:00
2015-06-07 13:06:18 -07:00
var currentSrc = mediaRenderer.currentSrc();
2013-05-23 18:47:07 -07:00
2015-03-29 11:31:28 -07:00
var playSessionId = getParameterByName('PlaySessionId', currentSrc);
2015-03-31 09:24:16 -07:00
var liveStreamId = getParameterByName('LiveStreamId', currentSrc);
2014-01-29 14:54:40 -07:00
2015-03-26 12:18:21 -07:00
if (params.AudioStreamIndex == null && params.SubtitleStreamIndex == null && params.Bitrate == null) {
2014-03-27 12:30:21 -07:00
2015-03-26 12:18:21 -07:00
currentSrc = replaceQueryString(currentSrc, 'starttimeticks', ticks || 0);
2015-06-07 13:06:18 -07:00
changeStreamToUrl(mediaRenderer, playSessionId, currentSrc, ticks);
2015-03-26 12:18:21 -07:00
return;
}
2014-04-11 20:48:57 -07:00
2015-03-26 12:18:21 -07:00
var deviceProfile = self.getDeviceProfile();
2014-04-11 20:48:57 -07:00
2015-03-26 13:31:57 -07:00
var audioStreamIndex = params.AudioStreamIndex == null ? (getParameterByName('AudioStreamIndex', currentSrc) || null) : params.AudioStreamIndex;
2015-03-26 12:18:21 -07:00
if (typeof (audioStreamIndex) == 'string') {
audioStreamIndex = parseInt(audioStreamIndex);
}
2014-04-11 20:48:57 -07:00
2015-03-26 13:31:57 -07:00
var subtitleStreamIndex = params.SubtitleStreamIndex == null ? (getParameterByName('SubtitleStreamIndex', currentSrc) || null) : params.SubtitleStreamIndex;
2015-03-26 12:18:21 -07:00
if (typeof (subtitleStreamIndex) == 'string') {
subtitleStreamIndex = parseInt(subtitleStreamIndex);
}
2014-04-02 14:55:19 -07:00
2015-05-25 10:32:22 -07:00
MediaController.getPlaybackInfo(self.currentItem.Id, deviceProfile, ticks, self.currentMediaSource, audioStreamIndex, subtitleStreamIndex, liveStreamId).done(function (result) {
2014-07-02 11:34:08 -07:00
2015-03-26 12:18:21 -07:00
if (validatePlaybackInfoResult(result)) {
2013-05-23 18:47:07 -07:00
2015-03-26 12:18:21 -07:00
self.currentMediaSource = result.MediaSources[0];
self.currentSubtitleStreamIndex = subtitleStreamIndex;
2013-05-23 18:47:07 -07:00
2015-04-01 19:47:59 -07:00
currentSrc = ApiClient.getUrl(self.currentMediaSource.TranscodingUrl);
2015-06-07 13:06:18 -07:00
changeStreamToUrl(mediaRenderer, playSessionId, currentSrc, ticks);
2015-03-26 12:18:21 -07:00
}
});
};
2013-05-23 18:47:07 -07:00
2015-06-07 13:06:18 -07:00
function changeStreamToUrl(mediaRenderer, playSessionId, url, newPositionTicks) {
2014-01-10 06:52:01 -07:00
clearProgressInterval();
2015-06-07 13:06:18 -07:00
$(mediaRenderer).off('ended.playbackstopped').off('ended.playnext').one("play", function () {
2013-05-23 18:47:07 -07:00
self.updateCanClientSeek(this);
2013-05-23 18:47:07 -07:00
$(this).on('ended.playbackstopped', self.onPlaybackStopped).one('ended.playnext', self.playNextAfterEnded);
self.startProgressInterval();
sendProgressUpdate();
2014-04-11 20:48:57 -07:00
});
2014-06-14 19:58:00 -07:00
if (self.currentItem.MediaType == "Video") {
2015-03-29 11:31:28 -07:00
ApiClient.stopActiveEncodings(playSessionId).done(function () {
self.startTimeTicksOffset = newPositionTicks;
2015-06-07 13:06:18 -07:00
mediaRenderer.setCurrentSrc(url);
});
self.updateTextStreamUrls(newPositionTicks || 0);
} else {
self.startTimeTicksOffset = newPositionTicks;
2015-06-07 13:06:18 -07:00
mediaRenderer.setCurrentSrc(url);
2013-05-23 18:47:07 -07:00
}
}
2013-04-30 12:13:06 -07:00
self.setCurrentTime = function (ticks, positionSlider, currentTimeElement) {
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
2014-03-31 14:43:49 -07:00
if (self.currentDurationTicks) {
2013-05-23 13:09:01 -07:00
2014-03-31 14:43:49 -07:00
timeText += " / " + Dashboard.getDisplayTime(self.currentDurationTicks);
2013-05-23 13:09:01 -07:00
if (positionSlider) {
2014-03-31 14:43:49 -07:00
var percent = ticks / self.currentDurationTicks;
2013-05-23 13:09:01 -07:00
percent *= 100;
positionSlider.val(percent).slider('enable').slider('refresh');
2013-04-30 12:13:06 -07:00
}
2013-05-24 07:35:15 -07:00
} else {
if (positionSlider) {
positionSlider.slider('disable').slider('refresh');
}
}
if (currentTimeElement) {
currentTimeElement.html(timeText);
2013-05-24 07:35:15 -07:00
}
2013-05-23 13:09:01 -07:00
2015-06-07 13:06:18 -07:00
var state = self.getPlayerStateInternal(self.currentMediaRenderer, self.currentItem, self.currentMediaSource);
$(self).trigger('positionchange', [state]);
};
2013-04-30 10:21:21 -07:00
2014-06-13 07:24:14 -07:00
var supportsTextTracks;
2014-06-11 19:38:40 -07:00
self.supportsTextTracks = function () {
2014-06-13 07:24:14 -07:00
if (supportsTextTracks == null) {
supportsTextTracks = document.createElement('video').textTracks != null;
}
// For now, until ready
return supportsTextTracks;
2014-06-11 19:38:40 -07:00
};
2014-03-29 08:40:32 -07:00
self.canQueueMediaType = function (mediaType) {
2013-04-08 21:16:32 -07:00
2014-06-11 12:31:33 -07:00
return self.currentItem && self.currentItem.MediaType == mediaType;
2014-03-29 08:40:32 -07:00
};
2013-05-24 19:45:12 -07:00
2014-03-29 12:02:43 -07:00
function translateItemsForPlayback(items) {
var deferred = $.Deferred();
var firstItem = items[0];
var promise;
if (firstItem.Type == "Playlist") {
2014-03-29 12:02:43 -07:00
promise = self.getItemsForPlayback({
ParentId: firstItem.Id,
});
}
else if (firstItem.Type == "MusicArtist") {
2014-04-02 14:55:19 -07:00
2014-03-29 12:02:43 -07:00
promise = self.getItemsForPlayback({
2015-03-13 10:25:28 -07:00
ArtistIds: firstItem.Id,
2014-03-29 12:02:43 -07:00
Filters: "IsNotFolder",
Recursive: true,
SortBy: "SortName",
MediaTypes: "Audio"
});
}
else if (firstItem.Type == "MusicGenre") {
2014-04-02 14:55:19 -07:00
2014-03-29 12:02:43 -07:00
promise = self.getItemsForPlayback({
Genres: firstItem.Name,
Filters: "IsNotFolder",
Recursive: true,
SortBy: "SortName",
MediaTypes: "Audio"
});
}
else if (firstItem.IsFolder) {
promise = self.getItemsForPlayback({
ParentId: firstItem.Id,
Filters: "IsNotFolder",
Recursive: true,
SortBy: "SortName",
MediaTypes: "Audio,Video"
});
}
2014-03-29 12:02:43 -07:00
if (promise) {
promise.done(function (result) {
deferred.resolveWith(null, [result.Items]);
});
} else {
deferred.resolveWith(null, [items]);
}
return deferred.promise();
}
2014-03-29 08:40:32 -07:00
self.play = function (options) {
2013-05-24 19:45:12 -07:00
2014-03-29 08:40:32 -07:00
Dashboard.getCurrentUser().done(function (user) {
2014-03-29 08:40:32 -07:00
if (options.items) {
2014-03-29 12:02:43 -07:00
translateItemsForPlayback(options.items).done(function (items) {
2014-08-01 19:34:45 -07:00
self.playWithIntros(items, options, user);
2014-03-29 12:02:43 -07:00
});
2013-06-07 09:06:32 -07:00
2014-03-29 08:40:32 -07:00
} else {
2013-06-07 09:06:32 -07:00
2014-03-29 08:40:32 -07:00
self.getItemsForPlayback({
2013-06-07 09:06:32 -07:00
2014-03-29 08:40:32 -07:00
Ids: options.ids.join(',')
2014-03-29 08:40:32 -07:00
}).done(function (result) {
2013-05-24 19:45:12 -07:00
2014-03-29 12:02:43 -07:00
translateItemsForPlayback(result.Items).done(function (items) {
2014-08-01 19:34:45 -07:00
self.playWithIntros(items, options, user);
2014-03-29 12:02:43 -07:00
});
2013-06-07 09:06:32 -07:00
2014-03-29 08:40:32 -07:00
});
}
});
};
2014-08-01 19:34:45 -07:00
self.playWithIntros = function (items, options, user) {
var firstItem = items[0];
if (options.startPositionTicks || firstItem.MediaType !== 'Video' || !self.canAutoPlayVideo()) {
2015-03-03 00:03:17 -07:00
self.playInternal(firstItem, options.startPositionTicks, function () {
self.setPlaylistState(0, items);
2015-03-03 00:03:17 -07:00
});
2014-08-21 08:55:35 -07:00
return;
2014-08-01 19:34:45 -07:00
}
ApiClient.getJSON(ApiClient.getUrl('Users/' + user.Id + '/Items/' + firstItem.Id + '/Intros')).done(function (intros) {
items = intros.Items.concat(items);
2015-03-03 00:03:17 -07:00
self.playInternal(items[0], options.startPositionTicks, function () {
self.setPlaylistState(0, items);
2015-03-03 00:03:17 -07:00
});
2014-08-01 19:34:45 -07:00
});
};
2014-03-22 09:16:43 -07:00
function getOptimalMediaSource(mediaType, versions) {
2014-03-20 21:52:46 -07:00
var optimalVersion = versions.filter(function (v) {
2014-03-20 21:52:46 -07:00
2015-05-25 10:32:22 -07:00
v.enableDirectPlay = MediaController.supportsDirectPlay(v);
2014-03-20 21:52:46 -07:00
return v.enableDirectPlay;
2015-03-16 21:08:09 -07:00
})[0];
2015-03-07 22:37:48 -07:00
if (!optimalVersion) {
2015-03-07 22:37:48 -07:00
optimalVersion = versions.filter(function (v) {
return v.SupportsDirectStream;
2015-03-07 22:37:48 -07:00
2014-03-20 21:52:46 -07:00
})[0];
}
2014-03-20 20:31:40 -07:00
2015-03-03 00:03:17 -07:00
return optimalVersion || versions.filter(function (s) {
return s.SupportsTranscoding;
})[0];
2014-03-20 20:31:40 -07:00
}
2013-06-07 09:06:32 -07:00
2015-04-07 21:01:52 -07:00
self.createStreamInfo = function (type, item, mediaSource, startPosition) {
var mediaUrl;
var contentType;
var startTimeTicksOffset = 0;
var startPositionInSeekParam = startPosition ? (startPosition / 10000000) : 0;
var seekParam = startPositionInSeekParam ? '#t=' + startPositionInSeekParam : '';
2015-05-18 18:46:31 -07:00
var playMethod = 'Transcode';
2015-04-07 21:01:52 -07:00
if (type == 'Video') {
contentType = 'video/' + mediaSource.Container;
if (mediaSource.enableDirectPlay) {
2015-05-31 11:22:51 -07:00
mediaUrl = FileSystem.translateFilePath(mediaSource.Path);
2015-05-18 18:46:31 -07:00
playMethod = 'DirectPlay';
2015-05-31 11:22:51 -07:00
} else {
if (mediaSource.SupportsDirectStream) {
mediaUrl = ApiClient.getUrl('Videos/' + item.Id + '/stream.' + mediaSource.Container, {
Static: true,
mediaSourceId: mediaSource.Id,
api_key: ApiClient.accessToken()
});
mediaUrl += seekParam;
2015-05-18 18:46:31 -07:00
playMethod = 'DirectStream';
} else {
startTimeTicksOffset = startPosition || 0;
2015-04-01 19:47:59 -07:00
mediaUrl = ApiClient.getUrl(mediaSource.TranscodingUrl);
if (mediaSource.TranscodingSubProtocol == 'hls') {
mediaUrl += seekParam;
contentType = 'application/x-mpegURL';
} else {
contentType = 'video/' + mediaSource.TranscodingContainer;
}
}
}
} else {
contentType = 'audio/' + mediaSource.Container;
if (mediaSource.enableDirectPlay) {
2015-05-31 11:22:51 -07:00
mediaUrl = FileSystem.translateFilePath(mediaSource.Path);
2015-05-18 18:46:31 -07:00
playMethod = 'DirectPlay';
2015-05-31 11:22:51 -07:00
} else {
var isDirectStream = mediaSource.SupportsDirectStream;
if (isDirectStream) {
var outputContainer = (mediaSource.Container || '').toLowerCase();
mediaUrl = ApiClient.getUrl('Audio/' + item.Id + '/stream.' + outputContainer, {
mediaSourceId: mediaSource.Id,
deviceId: ApiClient.deviceId(),
api_key: ApiClient.accessToken()
});
mediaUrl += "&static=true" + seekParam;
2015-05-18 18:46:31 -07:00
playMethod = 'DirectStream';
} else {
contentType = 'audio/' + mediaSource.TranscodingContainer;
2015-04-01 19:47:59 -07:00
mediaUrl = ApiClient.getUrl(mediaSource.TranscodingUrl);
}
startTimeTicksOffset = startPosition || 0;
}
}
return {
url: mediaUrl,
2015-05-25 10:32:22 -07:00
mimeType: contentType,
startTimeTicksOffset: startTimeTicksOffset,
2015-05-18 18:46:31 -07:00
startPositionInSeekParam: startPositionInSeekParam,
playMethod: playMethod
};
};
2015-03-03 00:03:17 -07:00
self.playInternal = function (item, startPosition, callback) {
2013-07-11 13:25:12 -07:00
if (item == null) {
throw new Error("item cannot be null");
}
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
2015-03-07 22:37:48 -07:00
if (item.MediaType !== 'Audio' && item.MediaType !== 'Video') {
throw new Error("Unrecognized media type");
}
2015-03-25 21:44:24 -07:00
if (item.IsPlaceHolder) {
2015-05-19 12:15:40 -07:00
MediaController.showPlaybackInfoErrorMessage('PlaceHolder');
2015-03-25 21:44:24 -07:00
return;
}
var deviceProfile = self.getDeviceProfile();
2015-05-06 20:11:51 -07:00
if (item.MediaType === "Video") {
Dashboard.showModalLoadingMsg();
}
2015-04-14 08:26:02 -07:00
2015-05-25 10:32:22 -07:00
MediaController.getPlaybackInfo(item.Id, deviceProfile, startPosition).done(function (playbackInfoResult) {
2015-03-07 22:37:48 -07:00
2015-04-13 09:21:10 -07:00
if (validatePlaybackInfoResult(playbackInfoResult)) {
2013-04-08 21:16:32 -07:00
2015-04-13 09:21:10 -07:00
var mediaSource = getOptimalMediaSource(item.MediaType, playbackInfoResult.MediaSources);
2014-11-18 19:45:12 -07:00
2015-03-07 22:37:48 -07:00
if (mediaSource) {
2015-02-05 22:39:07 -07:00
2015-03-29 09:45:16 -07:00
if (mediaSource.RequiresOpening) {
2014-11-18 19:45:12 -07:00
2015-05-25 10:32:22 -07:00
MediaController.getLiveStream(item.Id, playbackInfoResult.PlaySessionId, deviceProfile, startPosition, mediaSource, null, null).done(function (openLiveStreamResult) {
2015-03-03 00:03:17 -07:00
2015-05-25 10:32:22 -07:00
openLiveStreamResult.MediaSource.enableDirectPlay = MediaController.supportsDirectPlay(openLiveStreamResult.MediaSource);
2015-04-13 09:21:10 -07:00
2015-03-29 09:45:16 -07:00
playInternalPostMediaSourceSelection(item, openLiveStreamResult.MediaSource, startPosition, callback);
2015-03-28 21:56:39 -07:00
});
2015-03-03 00:03:17 -07:00
2015-03-28 21:56:39 -07:00
} else {
playInternalPostMediaSourceSelection(item, mediaSource, startPosition, callback);
2015-03-07 22:37:48 -07:00
}
} else {
2015-05-06 20:11:51 -07:00
Dashboard.hideModalLoadingMsg();
2015-05-19 12:15:40 -07:00
MediaController.showPlaybackInfoErrorMessage('NoCompatibleStream');
2015-03-03 00:03:17 -07:00
}
}
2014-03-20 20:31:40 -07:00
2015-03-07 22:37:48 -07:00
});
};
2015-03-28 21:56:39 -07:00
function playInternalPostMediaSourceSelection(item, mediaSource, startPosition, callback) {
2015-05-06 20:11:51 -07:00
Dashboard.hideModalLoadingMsg();
2015-04-14 08:26:02 -07:00
2015-03-28 21:56:39 -07:00
self.currentMediaSource = mediaSource;
self.currentItem = item;
if (item.MediaType === "Video") {
2015-04-28 06:56:57 -07:00
self.playVideo(item, self.currentMediaSource, startPosition);
2015-03-28 21:56:39 -07:00
} else if (item.MediaType === "Audio") {
2015-06-07 13:06:18 -07:00
self.currentMediaRenderer = playAudio(item, self.currentMediaSource, startPosition);
2015-03-28 21:56:39 -07:00
self.currentDurationTicks = self.currentMediaSource.RunTimeTicks;
}
if (callback) {
callback();
}
}
2015-03-03 00:03:17 -07:00
function validatePlaybackInfoResult(result) {
2015-03-06 20:53:31 -07:00
if (result.ErrorCode) {
2015-05-19 12:15:40 -07:00
MediaController.showPlaybackInfoErrorMessage(result.ErrorCode);
2015-03-06 20:53:31 -07:00
return false;
}
2015-03-03 00:03:17 -07:00
return true;
}
2015-05-08 20:48:43 -07:00
self.getPosterUrl = function (item) {
2014-04-13 10:27:13 -07:00
2015-05-21 13:53:14 -07:00
// Safari often shows the poster under the video, which doesn't look good
if ($.browser.safari) {
return null;
}
2015-05-08 20:48:43 -07:00
var screenWidth = Math.max(screen.height, screen.width);
2014-04-13 10:27:13 -07:00
2015-05-08 20:48:43 -07:00
if (item.BackdropImageTags && item.BackdropImageTags.length) {
2014-04-13 10:27:13 -07:00
2015-05-08 20:48:43 -07:00
return ApiClient.getScaledImageUrl(item.Id, {
type: "Backdrop",
index: 0,
maxWidth: screenWidth,
tag: item.BackdropImageTags[0]
});
2014-04-13 10:27:13 -07:00
}
2015-05-08 20:48:43 -07:00
else if (item.ParentBackdropItemId && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length) {
return ApiClient.getScaledImageUrl(item.ParentBackdropItemId, {
type: 'Backdrop',
index: 0,
maxWidth: screenWidth,
tag: item.ParentBackdropImageTags[0]
});
2014-04-13 10:27:13 -07:00
}
2015-05-08 20:48:43 -07:00
return null;
2014-04-13 10:27:13 -07:00
};
self.displayContent = function (options) {
2014-04-14 20:54:52 -07:00
2014-04-13 10:27:13 -07:00
// Handle it the same as a remote control command
2014-08-25 19:30:52 -07:00
Dashboard.onBrowseCommand(options);
2013-04-10 14:03:28 -07:00
};
2013-06-07 09:06:32 -07:00
self.getItemsForPlayback = function (query) {
var userId = Dashboard.getCurrentUserId();
2015-02-24 11:25:19 -07:00
if (query.Ids && query.Ids.split(',').length == 1) {
var deferred = DeferredBuilder.Deferred();
ApiClient.getItem(userId, query.Ids.split(',')).done(function (item) {
deferred.resolveWith(null, [
{
Items: [item],
TotalRecordCount: 1
}]);
});
2013-06-07 09:06:32 -07:00
2015-02-24 11:25:19 -07:00
return deferred.promise();
}
else {
query.Limit = query.Limit || 100;
query.Fields = getItemFields;
query.ExcludeLocationTypes = "Virtual";
return ApiClient.getItems(userId, query);
}
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-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-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
2015-03-03 00:03:17 -07:00
self.playInternal(newItem, 0, function () {
self.setPlaylistState(i);
2013-06-07 09:06:32 -07:00
});
2013-04-30 10:21:21 -07:00
};
// Set currentPlaylistIndex and playlist. Using a method allows for overloading in derived player implementations
self.setPlaylistState = function (i, items) {
if (!isNaN(i)) {
currentPlaylistIndex = i;
}
if (items) {
self.playlist = items;
}
if (self.updatePlaylistUi) {
self.updatePlaylistUi();
}
};
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
if (newItem) {
2014-07-17 15:21:35 -07:00
2014-08-10 15:13:17 -07:00
console.log('playing next track');
2015-03-03 00:03:17 -07:00
self.playInternal(newItem, 0, function () {
self.setPlaylistState(newIndex);
});
}
2013-05-23 13:09:01 -07:00
};
2013-08-09 08:55:22 -07:00
self.previousTrack = function () {
var newIndex = currentPlaylistIndex - 1;
if (newIndex >= 0) {
var newItem = self.playlist[newIndex];
if (newItem) {
2015-03-03 00:03:17 -07:00
self.playInternal(newItem, 0, function () {
self.setPlaylistState(newIndex);
});
}
}
};
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
};
2014-03-29 08:40:32 -07:00
self.queue = function (options) {
2013-06-07 09:06:32 -07:00
2015-06-07 13:06:18 -07:00
if (!self.playlist.length) {
2014-03-29 08:40:32 -07:00
self.play(options);
2014-01-18 10:58:05 -07:00
return;
}
2014-01-29 14:54:40 -07:00
2014-03-29 08:40:32 -07:00
Dashboard.getCurrentUser().done(function (user) {
2013-06-07 09:06:32 -07:00
2014-03-29 08:40:32 -07:00
if (options.items) {
2014-03-29 12:02:43 -07:00
translateItemsForPlayback(options.items).done(function (items) {
self.queueItems(items);
});
2014-03-29 08:40:32 -07:00
} else {
2013-06-07 09:06:32 -07:00
self.getItemsForPlayback({
2014-03-29 08:40:32 -07:00
Ids: options.ids.join(',')
2013-06-07 09:06:32 -07:00
}).done(function (result) {
2014-03-29 12:02:43 -07:00
translateItemsForPlayback(result.Items).done(function (items) {
2013-06-07 09:06:32 -07:00
2014-03-29 12:02:43 -07:00
self.queueItems(items);
});
2013-06-07 09:06:32 -07:00
2014-03-29 08:40:32 -07:00
});
2013-06-07 09:06:32 -07:00
}
2013-05-23 13:09:01 -07:00
});
};
2014-03-29 08:40:32 -07:00
self.queueNext = function (options) {
2013-08-08 07:53:25 -07:00
2015-06-07 13:06:18 -07:00
if (!self.playlist.length) {
2014-03-29 08:40:32 -07:00
self.play(options);
return;
}
2013-08-08 07:53:25 -07:00
2014-03-29 08:40:32 -07:00
Dashboard.getCurrentUser().done(function (user) {
2013-08-08 07:53:25 -07:00
2014-03-29 08:40:32 -07:00
if (options.items) {
2013-08-08 07:53:25 -07:00
2014-03-29 08:40:32 -07:00
self.queueItemsNext(options.items);
2013-08-08 07:53:25 -07:00
2014-03-29 08:40:32 -07:00
} else {
self.getItemsForPlayback({
2013-08-08 07:53:25 -07:00
2014-03-29 08:40:32 -07:00
Ids: options.ids.join(',')
}).done(function (result) {
options.items = result.Items;
self.queueItemsNext(options.items);
});
}
});
2013-08-08 07:53:25 -07:00
};
2013-05-23 13:09:01 -07:00
self.pause = function () {
2014-04-13 11:25:22 -07:00
2015-06-07 13:06:18 -07:00
self.currentMediaRenderer.pause();
2013-05-23 13:09:01 -07:00
};
self.unpause = function () {
2015-06-07 13:06:18 -07:00
self.currentMediaRenderer.unpause();
2013-05-23 13:09:01 -07:00
};
self.seek = function (position) {
2013-07-25 12:43:40 -07:00
self.changeStream(position);
};
2013-08-09 08:55:22 -07:00
2013-05-23 13:09:01 -07:00
self.mute = function () {
self.setVolume(0);
2013-05-23 13:09:01 -07:00
};
self.unMute = function () {
self.setVolume(self.getSavedVolume() * 100);
};
2014-11-13 23:27:10 -07:00
self.volume = function () {
2015-06-07 13:06:18 -07:00
return self.currentMediaRenderer.volume() * 100;
2014-10-22 21:26:01 -07:00
};
self.toggleMute = function () {
2015-06-07 13:06:18 -07:00
if (self.currentMediaRenderer) {
2014-04-30 20:24:55 -07:00
console.log('MediaPlayer toggling mute');
2014-10-22 21:26:01 -07:00
if (self.volume()) {
self.mute();
} else {
self.unMute();
}
}
};
2013-08-27 22:44:43 -07:00
self.volumeDown = function () {
2015-06-07 13:06:18 -07:00
if (self.currentMediaRenderer) {
2014-10-22 21:26:01 -07:00
self.setVolume(Math.max(self.volume() - 2, 0));
}
};
2013-08-27 22:44:43 -07:00
self.volumeUp = function () {
2015-06-07 13:06:18 -07:00
if (self.currentMediaRenderer) {
2014-10-22 21:26:01 -07:00
self.setVolume(Math.min(self.volume() + 2, 100));
}
};
// Sets volume using a 0-100 scale
self.setVolume = function (val) {
2015-06-07 13:06:18 -07:00
if (self.currentMediaRenderer) {
2014-04-30 20:24:55 -07:00
console.log('MediaPlayer setting volume to ' + val);
2015-06-07 13:06:18 -07:00
self.currentMediaRenderer.volume(val / 100);
2015-06-07 13:06:18 -07:00
self.onVolumeChanged(self.currentMediaRenderer);
2015-06-07 13:06:18 -07:00
//self.saveVolume();
}
2013-04-30 10:21:21 -07:00
};
self.saveVolume = function (val) {
if (val) {
2014-07-15 12:16:16 -07:00
store.setItem("volume", val);
}
};
self.getSavedVolume = function () {
2014-07-15 12:16:16 -07:00
return store.getItem("volume") || 0.5;
};
2014-03-29 08:40:32 -07:00
self.shuffle = function (id) {
var userId = Dashboard.getCurrentUserId();
ApiClient.getItem(userId, id).done(function (item) {
var query = {
UserId: userId,
Fields: getItemFields,
2014-11-02 20:38:43 -07:00
Limit: 100,
2014-03-29 08:40:32 -07:00
Filters: "IsNotFolder",
Recursive: true,
SortBy: "Random"
};
if (item.Type == "MusicArtist") {
2014-03-29 08:40:32 -07:00
query.MediaTypes = "Audio";
2015-03-13 10:25:28 -07:00
query.ArtistIds = item.Id;
2014-03-29 08:40:32 -07:00
}
else if (item.Type == "MusicGenre") {
query.MediaTypes = "Audio";
query.Genres = item.Name;
}
else if (item.IsFolder) {
query.ParentId = id;
}
else {
2014-03-29 08:40:32 -07:00
return;
}
self.getItemsForPlayback(query).done(function (result) {
self.play({ items: result.Items });
});
});
};
self.instantMix = function (id) {
var userId = Dashboard.getCurrentUserId();
ApiClient.getItem(userId, id).done(function (item) {
var promise;
2014-11-02 20:38:43 -07:00
var itemLimit = 100;
2014-03-29 08:40:32 -07:00
if (item.Type == "MusicArtist") {
2014-08-18 18:42:53 -07:00
promise = ApiClient.getInstantMixFromArtist({
2014-03-29 08:40:32 -07:00
UserId: Dashboard.getCurrentUserId(),
Fields: getItemFields,
2014-11-02 20:38:43 -07:00
Limit: itemLimit,
2014-08-18 18:42:53 -07:00
Id: id
2014-03-29 08:40:32 -07:00
});
}
else if (item.Type == "MusicGenre") {
2014-08-18 18:42:53 -07:00
promise = ApiClient.getInstantMixFromMusicGenre({
2014-03-29 08:40:32 -07:00
UserId: Dashboard.getCurrentUserId(),
Fields: getItemFields,
2014-11-02 20:38:43 -07:00
Limit: itemLimit,
2014-08-18 18:42:53 -07:00
Id: id
2014-03-29 08:40:32 -07:00
});
}
else if (item.Type == "MusicAlbum") {
promise = ApiClient.getInstantMixFromAlbum(id, {
2014-12-12 20:56:30 -07:00
UserId: Dashboard.getCurrentUserId(),
Fields: getItemFields,
Limit: itemLimit
});
}
else if (item.Type == "Playlist") {
promise = ApiClient.getInstantMixFromPlaylist(id, {
2014-03-29 08:40:32 -07:00
UserId: Dashboard.getCurrentUserId(),
Fields: getItemFields,
2014-11-02 20:38:43 -07:00
Limit: itemLimit
2014-03-29 08:40:32 -07:00
});
}
else if (item.Type == "Audio") {
promise = ApiClient.getInstantMixFromSong(id, {
UserId: Dashboard.getCurrentUserId(),
Fields: getItemFields,
2014-11-02 20:38:43 -07:00
Limit: itemLimit
2014-03-29 08:40:32 -07:00
});
}
else {
return;
}
promise.done(function (result) {
self.play({ items: result.Items });
});
});
};
2013-04-10 14:03:28 -07:00
self.stop = function () {
2013-03-31 18:52:07 -07:00
2015-06-07 13:06:18 -07:00
var mediaRenderer = self.currentMediaRenderer;
2013-03-31 18:52:07 -07:00
2015-06-07 13:06:18 -07:00
if (mediaRenderer) {
2013-02-20 18:33:05 -07:00
2015-06-07 13:06:18 -07:00
mediaRenderer.pause();
2015-06-07 13:06:18 -07:00
$(mediaRenderer).off("ended.playnext").one("ended", function () {
2013-06-07 10:23:23 -07:00
2014-07-01 14:13:32 -07:00
$(this).off();
2015-06-07 13:06:18 -07:00
this.destroy();
self.currentMediaRenderer = null;
2014-07-01 14:13:32 -07:00
self.currentItem = null;
self.currentMediaSource = null;
2014-07-01 14:13:32 -07:00
}).trigger("ended");
} else {
2015-06-07 13:06:18 -07:00
self.currentMediaRenderer = null;
2014-06-11 12:31:33 -07:00
self.currentItem = null;
self.currentMediaSource = null;
2014-07-01 14:13:32 -07:00
}
2013-03-26 14:32:01 -07:00
2015-03-26 13:48:24 -07:00
if (self.isFullScreen()) {
self.exitFullScreen();
2013-12-29 19:41:22 -07:00
}
2015-03-26 13:48:24 -07:00
self.resetEnhancements();
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 () {
2015-06-07 13:06:18 -07:00
return self.playlist.length > 0;
2013-04-10 14:03:28 -07:00
};
2013-05-25 17:53:51 -07:00
2014-04-13 10:27:13 -07:00
self.getPlayerState = function () {
var deferred = $.Deferred();
2015-06-07 13:06:18 -07:00
var result = self.getPlayerStateInternal(self.currentMediaRenderer, self.currentItem, self.currentMediaSource);
deferred.resolveWith(null, [result]);
return deferred.promise();
};
2015-06-07 13:06:18 -07:00
self.getPlayerStateInternal = function (mediaRenderer, item, mediaSource) {
2014-04-22 10:25:54 -07:00
var state = {
PlayState: {}
};
2015-06-07 13:06:18 -07:00
if (mediaRenderer) {
2015-06-07 13:06:18 -07:00
state.PlayState.VolumeLevel = mediaRenderer.volume() * 100;
state.PlayState.IsMuted = mediaRenderer.volume() == 0;
state.PlayState.IsPaused = mediaRenderer.paused();
state.PlayState.PositionTicks = self.getCurrentTicks(mediaRenderer);
2014-04-22 10:25:54 -07:00
2015-06-07 13:06:18 -07:00
var currentSrc = mediaRenderer.currentSrc();
2014-04-22 10:25:54 -07:00
if (currentSrc) {
var audioStreamIndex = getParameterByName('AudioStreamIndex', currentSrc);
if (audioStreamIndex) {
state.PlayState.AudioStreamIndex = parseInt(audioStreamIndex);
}
2014-06-11 12:31:33 -07:00
state.PlayState.SubtitleStreamIndex = self.currentSubtitleStreamIndex;
2014-04-22 10:25:54 -07:00
state.PlayState.PlayMethod = getParameterByName('static', currentSrc) == 'true' ?
'DirectStream' :
'Transcode';
2015-03-29 11:38:18 -07:00
state.PlayState.LiveStreamId = getParameterByName('LiveStreamId', currentSrc);
2015-04-01 14:55:50 -07:00
state.PlayState.PlaySessionId = getParameterByName('PlaySessionId', currentSrc);
2014-04-22 10:25:54 -07:00
}
}
if (mediaSource) {
2014-04-22 10:25:54 -07:00
state.PlayState.MediaSourceId = mediaSource.Id;
state.NowPlayingItem = {
RunTimeTicks: mediaSource.RunTimeTicks
};
2014-04-22 10:25:54 -07:00
state.PlayState.CanSeek = mediaSource.RunTimeTicks && mediaSource.RunTimeTicks > 0;
}
if (item) {
2015-05-25 10:32:22 -07:00
state.NowPlayingItem = self.getNowPlayingItemForReporting(item, mediaSource);
}
2014-04-27 18:57:29 -07:00
2015-05-25 10:32:22 -07:00
return state;
};
2014-04-22 10:25:54 -07:00
2015-05-25 10:32:22 -07:00
self.getNowPlayingItemForReporting = function (item, mediaSource) {
2015-05-25 10:32:22 -07:00
var nowPlayingItem = {};
2015-05-25 10:32:22 -07:00
nowPlayingItem.RunTimeTicks = mediaSource.RunTimeTicks;
2014-06-28 12:35:30 -07:00
2015-05-25 10:32:22 -07:00
nowPlayingItem.Id = item.Id;
nowPlayingItem.MediaType = item.MediaType;
nowPlayingItem.Type = item.Type;
nowPlayingItem.Name = item.Name;
2015-05-25 10:32:22 -07:00
nowPlayingItem.IndexNumber = item.IndexNumber;
nowPlayingItem.IndexNumberEnd = item.IndexNumberEnd;
nowPlayingItem.ParentIndexNumber = item.ParentIndexNumber;
nowPlayingItem.ProductionYear = item.ProductionYear;
nowPlayingItem.PremiereDate = item.PremiereDate;
nowPlayingItem.SeriesName = item.SeriesName;
nowPlayingItem.Album = item.Album;
nowPlayingItem.Artists = item.Artists;
2014-04-13 10:27:13 -07:00
2015-05-25 10:32:22 -07:00
var imageTags = item.ImageTags || {};
2014-04-13 10:27:13 -07:00
2015-05-25 10:32:22 -07:00
if (item.SeriesPrimaryImageTag) {
2015-05-25 10:32:22 -07:00
nowPlayingItem.PrimaryImageItemId = item.SeriesId;
nowPlayingItem.PrimaryImageTag = item.SeriesPrimaryImageTag;
}
else if (imageTags.Primary) {
2015-05-25 10:32:22 -07:00
nowPlayingItem.PrimaryImageItemId = item.Id;
nowPlayingItem.PrimaryImageTag = imageTags.Primary;
}
else if (item.AlbumPrimaryImageTag) {
2015-05-25 10:32:22 -07:00
nowPlayingItem.PrimaryImageItemId = item.AlbumId;
nowPlayingItem.PrimaryImageTag = item.AlbumPrimaryImageTag;
}
else if (item.SeriesPrimaryImageTag) {
2015-05-25 10:32:22 -07:00
nowPlayingItem.PrimaryImageItemId = item.SeriesId;
nowPlayingItem.PrimaryImageTag = item.SeriesPrimaryImageTag;
}
2014-06-28 12:35:30 -07:00
2015-05-25 10:32:22 -07:00
if (item.BackdropImageTags && item.BackdropImageTags.length) {
2014-06-28 12:35:30 -07:00
2015-05-25 10:32:22 -07:00
nowPlayingItem.BackdropItemId = item.Id;
nowPlayingItem.BackdropImageTag = item.BackdropImageTags[0];
}
else if (item.ParentBackdropImageTags && item.ParentBackdropImageTags.length) {
nowPlayingItem.BackdropItemId = item.ParentBackdropItemId;
nowPlayingItem.BackdropImageTag = item.ParentBackdropImageTags[0];
}
2014-06-28 12:35:30 -07:00
2015-05-25 10:32:22 -07:00
if (imageTags.Thumb) {
nowPlayingItem.ThumbItemId = item.Id;
nowPlayingItem.ThumbImageTag = imageTags.Thumb;
}
2015-05-25 10:32:22 -07:00
if (imageTags.Logo) {
nowPlayingItem.LogoItemId = item.Id;
nowPlayingItem.LogoImageTag = imageTags.Logo;
}
else if (item.ParentLogoImageTag) {
nowPlayingItem.LogoItemId = item.ParentLogoItemId;
nowPlayingItem.LogoImageTag = item.ParentLogoImageTag;
}
return nowPlayingItem;
};
self.beginPlayerUpdates = function () {
// Nothing to setup here
};
self.endPlayerUpdates = function () {
// Nothing to setup here
};
2015-06-07 13:06:18 -07:00
self.onPlaybackStart = function (mediaRenderer, item, mediaSource) {
2015-06-07 13:06:18 -07:00
self.updateCanClientSeek(mediaRenderer);
2015-06-07 13:06:18 -07:00
var state = self.getPlayerStateInternal(mediaRenderer, item, mediaSource);
$(self).trigger('playbackstart', [state]);
2014-05-07 11:38:50 -07:00
self.startProgressInterval();
};
2015-06-07 13:06:18 -07:00
self.onVolumeChanged = function (mediaRenderer) {
2015-06-07 13:06:18 -07:00
self.saveVolume(mediaRenderer.volume());
2015-06-07 13:06:18 -07:00
var state = self.getPlayerStateInternal(mediaRenderer, self.currentItem, self.currentMediaSource);
$(self).trigger('volumechange', [state]);
};
2014-08-14 06:24:30 -07:00
self.cleanup = function () {
2014-08-10 15:13:17 -07:00
};
self.onPlaybackStopped = function () {
2014-08-10 15:13:17 -07:00
console.log('playback stopped');
2014-06-28 12:35:30 -07:00
$('body').removeClass('bodyWithPopupOpen');
2015-06-07 13:06:18 -07:00
var mediaRenderer = this;
2015-06-07 13:06:18 -07:00
$(mediaRenderer).off('.mediaplayerevent').off('ended.playbackstopped');
2015-06-07 13:06:18 -07:00
self.cleanup(mediaRenderer);
2014-08-10 15:13:17 -07:00
clearProgressInterval();
2014-06-11 12:31:33 -07:00
var item = self.currentItem;
var mediaSource = self.currentMediaSource;
if (item.MediaType == "Video") {
2015-03-20 10:29:18 -07:00
if (self.isFullScreen()) {
self.exitFullScreen();
}
self.resetEnhancements();
}
2015-06-07 13:06:18 -07:00
var state = self.getPlayerStateInternal(mediaRenderer, item, mediaSource);
$(self).trigger('playbackstop', [state]);
};
2015-06-07 13:06:18 -07:00
self.onPlaystateChange = function (mediaRenderer) {
2015-06-07 13:06:18 -07:00
var state = self.getPlayerStateInternal(mediaRenderer, self.currentItem, self.currentMediaSource);
$(self).trigger('playstatechange', [state]);
};
$(window).on("beforeunload", function () {
// Try to report playback stopped before the browser closes
2015-06-07 13:06:18 -07:00
if (self.currentItem && self.currentMediaRenderer && currentProgressInterval) {
2015-06-07 13:06:18 -07:00
self.onPlaybackStopped.call(self.currentMediaRenderer);
}
});
2014-05-07 11:38:50 -07:00
function sendProgressUpdate() {
2015-06-07 13:06:18 -07:00
var state = self.getPlayerStateInternal(self.currentMediaRenderer, self.currentItem, self.currentMediaSource);
2014-06-11 19:38:40 -07:00
2014-05-07 11:38:50 -07:00
var info = {
QueueableMediaTypes: state.NowPlayingItem.MediaType,
ItemId: state.NowPlayingItem.Id,
NowPlayingItem: state.NowPlayingItem
};
2014-04-30 08:07:02 -07:00
2014-05-07 11:38:50 -07:00
info = $.extend(info, state.PlayState);
ApiClient.reportPlaybackProgress(info);
2014-04-02 14:55:19 -07:00
}
function clearProgressInterval() {
if (currentProgressInterval) {
clearTimeout(currentProgressInterval);
currentProgressInterval = null;
}
2014-04-30 08:07:02 -07:00
}
2015-06-07 13:06:18 -07:00
self._canPlayWebm = null;
self.canPlayWebm = function () {
2015-06-07 18:23:56 -07:00
if (self._canPlayWebm == null) {
self._canPlayWebm = document.createElement('video').canPlayType('video/webm').replace(/no/, '');
}
2015-06-07 13:06:18 -07:00
return self._canPlayWebm;
2014-08-14 06:24:30 -07:00
};
2014-04-14 20:54:52 -07:00
self.canAutoPlayAudio = function () {
2015-05-28 16:37:43 -07:00
if (AppInfo.isNativeApp) {
2015-05-02 09:34:27 -07:00
return true;
}
2015-05-09 21:29:04 -07:00
if ($.browser.mobile) {
2014-04-14 20:54:52 -07:00
return false;
}
return true;
};
2015-06-07 13:06:18 -07:00
function getAudioRenderer() {
2015-06-07 13:06:18 -07:00
return new HtmlMediaRenderer('audio');
2014-04-02 14:55:19 -07:00
}
2015-05-22 12:16:14 -07:00
function onTimeUpdate() {
var currentTicks = self.getCurrentTicks(this);
self.setCurrentTime(currentTicks);
}
function playAudio(item, mediaSource, startPositionTicks) {
2015-03-07 22:37:48 -07:00
2015-04-07 21:01:52 -07:00
var streamInfo = self.createStreamInfo('Audio', item, mediaSource, startPositionTicks);
var audioUrl = streamInfo.url;
self.startTimeTicksOffset = streamInfo.startTimeTicksOffset;
2014-04-13 10:27:13 -07:00
var initialVolume = self.getSavedVolume();
2015-06-07 13:06:18 -07:00
var mediaRenderer = getAudioRenderer();
2015-06-07 13:06:18 -07:00
mediaRenderer.setCurrentSrc(audioUrl);
mediaRenderer.volume(initialVolume);
mediaRenderer.setPoster(self.getPosterUrl(item));
2015-06-07 13:06:18 -07:00
$(mediaRenderer).on("volumechange.mediaplayerevent", function () {
2014-08-10 15:13:17 -07:00
console.log('audio element event: volumechange');
self.onVolumeChanged(this);
2014-06-21 22:52:31 -07:00
}).one("playing.mediaplayerevent", function () {
2014-08-10 15:13:17 -07:00
console.log('audio element event: playing');
// For some reason this is firing at the start, so don't bind until playback has begun
$(this).on("ended.playbackstopped", self.onPlaybackStopped).one('ended.playnext', self.playNextAfterEnded);
self.onPlaybackStart(this, item, mediaSource);
2014-06-21 22:52:31 -07:00
}).on("pause.mediaplayerevent", function () {
2014-08-10 15:13:17 -07:00
console.log('audio element event: pause');
self.onPlaystateChange(this);
2014-11-13 23:27:10 -07:00
// In the event timeupdate isn't firing, at least we can update when this happens
self.setCurrentTime(self.getCurrentTicks());
2014-06-21 22:52:31 -07:00
}).on("playing.mediaplayerevent", function () {
2014-08-10 15:13:17 -07:00
console.log('audio element event: playing');
self.onPlaystateChange(this);
2014-11-13 23:27:10 -07:00
// In the event timeupdate isn't firing, at least we can update when this happens
self.setCurrentTime(self.getCurrentTicks());
2015-06-07 13:06:18 -07:00
}).on("timeupdate.mediaplayerevent", onTimeUpdate);
return mediaRenderer;
};
2014-03-22 09:16:43 -07:00
var getItemFields = "MediaSources,Chapters";
2015-05-18 09:40:20 -07:00
self.tryPair = function (target) {
var deferred = $.Deferred();
deferred.resolve();
return deferred.promise();
};
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
2015-05-21 13:53:14 -07:00
Dashboard.ready(function () {
2015-05-19 12:15:40 -07:00
window.MediaController.registerPlayer(window.MediaPlayer);
window.MediaController.setActivePlayer(window.MediaPlayer, window.MediaPlayer.getTargets()[0]);
});
2014-03-29 08:40:32 -07:00
2015-06-07 13:06:18 -07:00
})(document, setTimeout, clearTimeout, screen, window.appStorage, $, setInterval, window);
2015-06-07 18:23:56 -07:00
(function () {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function htmlMediaRenderer(type) {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
var mediaElement;
var self = this;
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function onEnded() {
$(self).trigger('ended');
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function onTimeUpdate() {
$(self).trigger('timeupdate');
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function onVolumeChange() {
$(self).trigger('volumechange');
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function onOneAudioPlaying() {
$('.mediaPlayerAudioContainer').hide();
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function onPlaying() {
$(self).trigger('playing');
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function onPlay() {
$(self).trigger('play');
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function onPause() {
$(self).trigger('pause');
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function onClick() {
$(self).trigger('click');
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function onDblClick() {
$(self).trigger('dblclick');
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function onError() {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
var errorCode = this.error ? this.error.code : '';
2015-06-07 13:06:18 -07:00
console.log('Media element error code: ' + errorCode);
$(self).trigger('error');
2015-06-07 18:23:56 -07:00
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function onLoadedMetadata() {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
// The IE video player won't autoplay without this
if ($.browser.msie) {
this.play();
}
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function onOneVideoPlaying() {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
var currentSrc = (this.currentSrc || '').toLowerCase();
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
var parts = currentSrc.split('#');
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
if (parts.length > 1) {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
var parts = parts[parts.length - 1].split('=');
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
if (parts.length == 2) {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
var startPositionInSeekParam = parseFloat(parts[1]);
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
// Appending #t=xxx to the query string doesn't seem to work with HLS
if (startPositionInSeekParam && currentSrc.indexOf('.m3u8') != -1) {
var element = this;
setTimeout(function () {
element.currentTime = startPositionInSeekParam;
}, 3000);
}
}
}
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function createAudioElement() {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
var elem = $('.mediaPlayerAudio');
2015-06-07 13:06:18 -07:00
if (!elem.length) {
2015-06-07 18:23:56 -07:00
var html = '';
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
var requiresControls = !MediaPlayer.canAutoPlayAudio();
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
if (requiresControls) {
html += '<div class="mediaPlayerAudioContainer"><div class="mediaPlayerAudioContainerInner">';;
} else {
html += '<div class="mediaPlayerAudioContainer" style="display:none;"><div class="mediaPlayerAudioContainerInner">';;
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
html += '<audio class="mediaPlayerAudio" crossorigin="anonymous" controls>';
html += '</audio></div></div>';
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
$(document.body).append(html);
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
elem = $('.mediaPlayerAudio');
2015-06-07 13:06:18 -07:00
}
return $(elem)
.on('timeupdate', onTimeUpdate)
.on('ended', onEnded)
.on('volumechange', onVolumeChange)
.one('playing', onOneAudioPlaying)
.on('play', onPlay)
.on('pause', onPause)
.on('playing', onPlaying)
.on('error', onError)[0];
2015-06-07 18:23:56 -07:00
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
function createVideoElement() {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
var elem = $('.itemVideo');
2015-06-07 13:06:18 -07:00
return $(elem)
.one('.loadedmetadata')
.one('playing', onOneVideoPlaying)
.on('timeupdate', onTimeUpdate)
.on('ended', onEnded)
.on('volumechange', onVolumeChange)
.on('play', onPlay)
.on('pause', onPause)
.on('playing', onPlaying)
.on('error', onError)[0];
2015-06-07 18:23:56 -07:00
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
self.currentTime = function (val) {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
if (mediaElement) {
if (val != null) {
mediaElement.currentTime = val;
return;
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
return mediaElement.currentTime;
}
};
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
self.duration = function (val) {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
if (mediaElement) {
return mediaElement.duration;
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
return null;
};
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
self.pause = function () {
if (mediaElement) {
mediaElement.pause();
}
};
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
self.unpause = function () {
if (mediaElement) {
mediaElement.play();
}
};
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
self.volume = function (val) {
if (mediaElement) {
if (val != null) {
mediaElement.volume = val;
return;
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
return mediaElement.volume;
}
};
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
self.setCurrentSrc = function (val) {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
var elem = mediaElement;
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
if (!elem) {
return;
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
if (!val) {
elem.src = null;
2015-06-07 13:06:18 -07:00
elem.src = "";
// When the browser regains focus it may start auto-playing the last video
if ($.browser.safari) {
elem.src = 'files/dummy.mp4';
elem.play();
}
2015-06-07 18:23:56 -07:00
return;
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
elem.src = val;
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
if (elem.tagName.toLowerCase() == 'audio') {
elem.play();
}
else {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
$(elem).one("loadedmetadata.mediaplayerevent", onLoadedMetadata);
}
};
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
self.currentSrc = function () {
if (mediaElement) {
return mediaElement.currentSrc;
}
};
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
self.paused = function () {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
if (mediaElement) {
return mediaElement.paused;
}
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
return false;
};
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
self.destroy = function () {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
self.setCurrentSrc(null);
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
var elem = mediaElement;
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
if (elem) {
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
$(elem).off();
2015-06-07 13:06:18 -07:00
2015-06-07 18:23:56 -07:00
if (elem.tagName.toLowerCase() != 'audio') {
$(elem).remove();
2015-06-07 13:06:18 -07:00
}
2015-06-07 18:23:56 -07:00
}
};
self.setPoster = function (url) {
var elem = mediaElement;
if (elem) {
elem.poster = url;
}
};
if (type == 'audio') {
mediaElement = createAudioElement();
}
else {
mediaElement = createVideoElement();
}
}
window.HtmlMediaRenderer = htmlMediaRenderer;
2015-06-07 13:06:18 -07:00
})();