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 testableVideoElement = document.createElement('video');
|
|
|
|
var currentProgressInterval;
|
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-06-23 21:18:02 -07:00
|
|
|
self.currentMediaElement = 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-01-03 21:53:49 -07:00
|
|
|
|
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 = [{
|
|
|
|
name: 'My Browser',
|
2014-10-25 11:32:58 -07:00
|
|
|
id: ConnectionManager.deviceId(),
|
2014-03-29 11:20:42 -07:00
|
|
|
playerName: self.name,
|
2014-04-05 10:01:04 -07:00
|
|
|
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-03-26 09:58:02 -07:00
|
|
|
var supportsAac = 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
|
|
|
|
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 });
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
self.getDeviceProfile = function () {
|
|
|
|
|
|
|
|
var qualityOption = self.getVideoQualityOptions().filter(function (q) {
|
|
|
|
return q.selected;
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
var bitrateSetting = AppSettings.maxStreamingBitrate();
|
|
|
|
|
|
|
|
var profile = {};
|
|
|
|
|
|
|
|
profile.MaxStreamingBitrate = bitrateSetting;
|
|
|
|
profile.MaxStaticBitrate = 40000000;
|
|
|
|
profile.MusicStreamingTranscodingBitrate = 128000;
|
|
|
|
|
|
|
|
profile.DirectPlayProfiles = [];
|
|
|
|
profile.DirectPlayProfiles.push({
|
|
|
|
Container: 'mp4',
|
|
|
|
Type: 'Video',
|
|
|
|
VideoCodec: 'h264',
|
|
|
|
AudioCodec: 'aac,mp3'
|
|
|
|
});
|
|
|
|
|
|
|
|
if ($.browser.chrome) {
|
|
|
|
profile.DirectPlayProfiles.push({
|
|
|
|
Container: 'mkv,m4v',
|
|
|
|
Type: 'Video',
|
|
|
|
VideoCodec: 'h264',
|
|
|
|
AudioCodec: 'aac,mp3'
|
|
|
|
});
|
|
|
|
profile.DirectPlayProfiles.push({
|
|
|
|
Container: 'flv',
|
|
|
|
Type: 'Video'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.DirectPlayProfiles.push({
|
|
|
|
Container: 'mp3',
|
|
|
|
Type: 'Audio'
|
|
|
|
});
|
|
|
|
|
|
|
|
if (supportsAac) {
|
|
|
|
profile.DirectPlayProfiles.push({
|
|
|
|
Container: 'aac',
|
|
|
|
Type: 'Audio'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.TranscodingProfiles = [];
|
|
|
|
profile.TranscodingProfiles.push({
|
|
|
|
Container: 'mp3',
|
|
|
|
Type: 'Audio',
|
|
|
|
AudioCodec: 'mp3',
|
|
|
|
Context: 'Streaming',
|
|
|
|
Protocol: 'http'
|
|
|
|
});
|
|
|
|
|
|
|
|
if (self.canPlayHls()) {
|
|
|
|
profile.TranscodingProfiles.push({
|
|
|
|
Container: 'ts',
|
|
|
|
Type: 'Video',
|
|
|
|
AudioCodec: 'aac',
|
|
|
|
VideoCodec: 'h264',
|
|
|
|
Context: 'Streaming',
|
|
|
|
Protocol: 'hls'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.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'
|
|
|
|
});
|
|
|
|
|
|
|
|
profile.ContainerProfiles = [];
|
|
|
|
|
|
|
|
var audioConditions = [];
|
|
|
|
if ($.browser.msie) {
|
|
|
|
audioConditions.push({
|
|
|
|
Condition: 'LessThanEqual',
|
|
|
|
Property: 'AudioChannels',
|
|
|
|
Value: '2'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.CodecProfiles = [];
|
|
|
|
profile.CodecProfiles.push({
|
|
|
|
Type: 'Audio',
|
|
|
|
Conditions: audioConditions
|
|
|
|
});
|
|
|
|
|
|
|
|
profile.CodecProfiles.push({
|
|
|
|
Type: 'VideoAudio',
|
|
|
|
Conditions: audioConditions
|
|
|
|
});
|
|
|
|
|
|
|
|
profile.CodecProfiles.push({
|
|
|
|
Type: 'Video',
|
|
|
|
Codec: 'h264',
|
|
|
|
Conditions: [
|
|
|
|
{
|
|
|
|
Condition: 'Equals',
|
|
|
|
Property: 'IsCabac',
|
|
|
|
Value: 'true'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Condition: 'NotEquals',
|
|
|
|
Property: 'IsAnamorphic',
|
|
|
|
Value: 'true'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Condition: 'EqualsAny',
|
|
|
|
Property: 'VideoProfile',
|
|
|
|
Value: 'high|main|baseline|constrained baseline'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Condition: 'LessThanEqual',
|
|
|
|
Property: 'VideoLevel',
|
|
|
|
Value: '41'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Condition: 'LessThanEqual',
|
|
|
|
Property: 'Width',
|
|
|
|
Value: qualityOption.maxWidth
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
profile.CodecProfiles.push({
|
|
|
|
Type: 'Video',
|
|
|
|
Codec: 'vpx',
|
|
|
|
Conditions: [
|
|
|
|
{
|
|
|
|
Condition: 'NotEquals',
|
|
|
|
Property: 'IsAnamorphic',
|
|
|
|
Value: 'true'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Condition: 'LessThanEqual',
|
|
|
|
Property: 'Width',
|
|
|
|
Value: qualityOption.maxWidth
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
// Subtitle profiles
|
|
|
|
// External vtt or burn in
|
|
|
|
profile.SubtitleProfiles = [];
|
|
|
|
if (self.supportsTextTracks()) {
|
|
|
|
profile.SubtitleProfiles.push({
|
|
|
|
Format: 'vtt',
|
|
|
|
Method: 'External'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
};
|
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.updateCanClientSeek = function (elem) {
|
2014-10-07 18:37:45 -07:00
|
|
|
|
2014-01-10 06:52:01 -07:00
|
|
|
var duration = elem.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;
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
2013-05-23 13:09:01 -07:00
|
|
|
|
2014-10-22 21:26:01 -07:00
|
|
|
self.getCurrentSrc = function (mediaElement) {
|
|
|
|
return mediaElement.currentSrc;
|
|
|
|
};
|
|
|
|
|
2014-03-08 01:09:45 -07:00
|
|
|
self.getCurrentTicks = function (mediaElement) {
|
2014-06-13 07:24:14 -07:00
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
var playerTime = Math.floor(10000000 * (mediaElement || self.currentMediaElement).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;
|
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.playNextAfterEnded = function () {
|
2013-06-07 10:23:23 -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-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 () {
|
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
if (self.currentMediaElement) {
|
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-03-20 01:34:54 -07:00
|
|
|
};
|
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-03-26 09:58:02 -07:00
|
|
|
self.canPlayHls = function () {
|
|
|
|
|
|
|
|
var media = testableVideoElement;
|
|
|
|
|
|
|
|
// safari
|
|
|
|
if (media.canPlayType('application/x-mpegURL').replace(/no/, '') ||
|
|
|
|
media.canPlayType('application/vnd.apple.mpegURL').replace(/no/, '')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2014-10-03 18:42:38 -07:00
|
|
|
self.getVideoTranscodingExtension = function (currentSrc) {
|
|
|
|
|
|
|
|
if (currentSrc) {
|
|
|
|
return self.getCurrentMediaExtension(currentSrc);
|
|
|
|
}
|
2014-01-08 21:45:09 -07:00
|
|
|
|
|
|
|
// safari
|
2015-03-26 09:58:02 -07:00
|
|
|
if (self.canPlayHls()) {
|
2014-01-08 21:45:09 -07:00
|
|
|
return '.m3u8';
|
|
|
|
}
|
|
|
|
|
2014-12-18 21:20:07 -07:00
|
|
|
// Chrome, Firefox or IE with plugin installed
|
2015-01-03 22:55:34 -07:00
|
|
|
// For some reason in chrome pausing mp4 is causing the video to fail.
|
|
|
|
// So for now it will have to prioritize webm
|
2015-02-05 22:39:07 -07:00
|
|
|
if (self.canPlayWebm()) {
|
2014-12-18 21:20:07 -07:00
|
|
|
|
2015-02-05 22:39:07 -07:00
|
|
|
if ($.browser.msie) {
|
|
|
|
return '.webm';
|
|
|
|
}
|
|
|
|
if ($.browser.chrome) {
|
2015-02-28 12:27:51 -07:00
|
|
|
return '.webm';
|
2015-02-05 22:39:07 -07:00
|
|
|
}
|
2015-02-24 11:25:19 -07:00
|
|
|
|
2015-02-20 08:27:33 -07:00
|
|
|
// Firefox suddenly having trouble with our webm
|
2015-03-02 12:46:28 -07:00
|
|
|
return '.webm';
|
2014-01-08 21:45:09 -07:00
|
|
|
}
|
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
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
var element = self.currentMediaElement;
|
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
|
|
|
|
2013-05-25 18:53:34 -07:00
|
|
|
element.currentTime = ticks / (1000 * 10000);
|
2015-03-26 11:23:46 -07:00
|
|
|
return;
|
|
|
|
}
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
params = params || {};
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
var currentSrc = element.currentSrc;
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
var currentStreamId = getParameterByName('StreamId', currentSrc);
|
2014-01-29 14:54:40 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
//if (self.currentItem.MediaType == "Video") {
|
2014-04-30 08:07:02 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
// transcodingExtension = self.getVideoTranscodingExtension(currentSrc);
|
2014-04-30 08:07:02 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
// if (params.AudioStreamIndex != null) {
|
|
|
|
// currentSrc = replaceQueryString(currentSrc, 'AudioStreamIndex', params.AudioStreamIndex);
|
|
|
|
// }
|
|
|
|
// if (params.SubtitleStreamIndex != null) {
|
|
|
|
// currentSrc = replaceQueryString(currentSrc, 'SubtitleStreamIndex', (params.SubtitleStreamIndex == -1 ? '' : params.SubtitleStreamIndex));
|
|
|
|
// }
|
2014-07-15 12:16:16 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
// var audioStreamIndex = params.AudioStreamIndex == null ? getParameterByName('AudioStreamIndex', currentSrc) : params.AudioStreamIndex;
|
|
|
|
// if (typeof (audioStreamIndex) == 'string') {
|
|
|
|
// audioStreamIndex = parseInt(audioStreamIndex);
|
|
|
|
// }
|
|
|
|
// var subtitleStreamIndex = self.currentSubtitleStreamIndex;
|
|
|
|
// 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
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
// var finalParams = self.getFinalVideoParams(self.currentMediaSource, bitrate, audioStreamIndex, subtitleStreamIndex, transcodingExtension);
|
2014-01-16 21:53:16 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
// currentSrc = replaceQueryString(currentSrc, 'VideoBitrate', finalParams.videoBitrate);
|
2014-03-27 12:30:21 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
// currentSrc = replaceQueryString(currentSrc, 'VideoCodec', finalParams.videoCodec);
|
2014-03-27 12:30:21 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
// currentSrc = replaceQueryString(currentSrc, 'profile', finalParams.profile || '');
|
|
|
|
// currentSrc = replaceQueryString(currentSrc, 'level', finalParams.level || '');
|
2014-04-11 20:48:57 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
// if (finalParams.isStatic) {
|
|
|
|
// currentSrc = currentSrc.replace('.webm', '.mp4').replace('.m3u8', '.mp4');
|
|
|
|
// currentSrc = replaceQueryString(currentSrc, 'ClientTime', '');
|
|
|
|
// } else {
|
|
|
|
// currentSrc = currentSrc.replace('.mp4', transcodingExtension).replace('.m4v', transcodingExtension).replace('.mkv', transcodingExtension).replace('.webm', transcodingExtension);
|
|
|
|
// currentSrc = replaceQueryString(currentSrc, 'ClientTime', new Date().getTime());
|
|
|
|
// }
|
2014-04-11 20:48:57 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
// currentSrc = replaceQueryString(currentSrc, 'AudioBitrate', finalParams.audioBitrate);
|
|
|
|
// currentSrc = replaceQueryString(currentSrc, 'Static', finalParams.isStatic);
|
|
|
|
// currentSrc = replaceQueryString(currentSrc, 'AudioCodec', finalParams.audioCodec);
|
|
|
|
// isStatic = finalParams.isStatic;
|
|
|
|
//}
|
2014-04-11 20:48:57 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
if (params.AudioStreamIndex == null && params.SubtitleStreamIndex == null && params.Bitrate == null) {
|
2014-04-02 14:55:19 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
var transcodingProfile = self.getDeviceProfile().TranscodingProfiles.filter(function (t) {
|
2014-07-02 11:34:08 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
return t.Type == self.currentItem.MediaType;
|
|
|
|
})[0];
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
} else {
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
currentSrc = replaceQueryString(currentSrc, 'starttimeticks', ticks || 0);
|
|
|
|
changeStreamToUrl(currentStreamId, currentSrc, ticks);
|
|
|
|
}
|
|
|
|
};
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
function changeStreamToUrl(currentStreamId, url, newPositionTicks) {
|
2014-01-10 06:52:01 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
clearProgressInterval();
|
2013-07-16 14:55:50 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
$(element).off('ended.playbackstopped').off('ended.playnext').one("play", function () {
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
self.updateCanClientSeek(this);
|
2013-05-23 18:47:07 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
$(this).on('ended.playbackstopped', self.onPlaybackStopped).one('ended.playnext', self.playNextAfterEnded);
|
2013-12-01 13:17:24 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
self.startProgressInterval();
|
|
|
|
sendProgressUpdate();
|
2014-04-11 20:48:57 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
});
|
2014-06-14 19:58:00 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
if (self.currentItem.MediaType == "Video") {
|
|
|
|
ApiClient.stopActiveEncodings(currentStreamId).done(function () {
|
|
|
|
|
|
|
|
self.startTimeTicksOffset = newPositionTicks;
|
|
|
|
element.src = url;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
self.updateTextStreamUrls(newPositionTicks || 0);
|
|
|
|
} else {
|
|
|
|
self.startTimeTicksOffset = newPositionTicks;
|
|
|
|
element.src = url;
|
|
|
|
element.play();
|
2013-05-23 18:47:07 -07:00
|
|
|
}
|
2015-03-26 11:23:46 -07:00
|
|
|
}
|
2013-04-30 12:13:06 -07:00
|
|
|
|
2014-04-11 08:36:25 -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
|
|
|
|
2014-04-11 08:36:25 -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;
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
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-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
var state = self.getPlayerStateInternal(self.currentMediaElement, self.currentItem, self.currentMediaSource);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
$(self).trigger('positionchange', [state]);
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
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
|
|
|
};
|
|
|
|
|
2015-03-26 09:58:02 -07:00
|
|
|
self.getVideoDirectPlayMethod = function (mediaSource, videoStream, audioStream, subtitleStream, bitrate) {
|
2014-01-08 13:29:09 -07:00
|
|
|
|
2014-04-02 14:55:19 -07:00
|
|
|
if (!mediaSource) {
|
|
|
|
throw new Error('Null mediaSource');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!videoStream) {
|
2014-10-07 18:37:45 -07:00
|
|
|
console.log('Cannot direct play without videoStream info');
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2014-10-07 18:37:45 -07:00
|
|
|
}
|
|
|
|
|
2014-10-22 21:26:01 -07:00
|
|
|
if (mediaSource.Protocol.toLowerCase() == "rtmp" || mediaSource.Protocol.toLowerCase() == "rtsp") {
|
2014-10-07 18:37:45 -07:00
|
|
|
//console.log('Transcoding because the content is not a video file');
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2014-04-02 14:55:19 -07:00
|
|
|
}
|
|
|
|
|
2014-10-07 18:37:45 -07:00
|
|
|
if (mediaSource.VideoType && mediaSource.VideoType != "VideoFile") {
|
|
|
|
//console.log('Transcoding because the content is not a video file');
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2014-01-08 13:29:09 -07:00
|
|
|
}
|
2014-01-29 14:54:40 -07:00
|
|
|
|
2014-08-31 12:15:33 -07:00
|
|
|
var isH264 = (videoStream.Codec || '').toLowerCase().indexOf('h264') != -1;
|
|
|
|
|
|
|
|
if (!isH264) {
|
2014-01-16 21:53:16 -07:00
|
|
|
console.log('Transcoding because the content is not h264');
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2014-01-08 13:29:09 -07:00
|
|
|
}
|
|
|
|
|
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.');
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2014-01-16 21:53:16 -07:00
|
|
|
}
|
2014-01-08 13:29:09 -07:00
|
|
|
|
2015-02-07 14:03:09 -07:00
|
|
|
if (subtitleStream && (!subtitleStream.SupportsExternalStream || !subtitleStream.IsTextSubtitleStream || !self.supportsTextTracks())) {
|
2014-01-16 21:53:16 -07:00
|
|
|
console.log('Transcoding because subtitles are required');
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2014-01-16 21:53:16 -07:00
|
|
|
}
|
2014-01-29 14:54:40 -07:00
|
|
|
|
2014-10-22 21:26:01 -07:00
|
|
|
if (videoStream.IsCabac != null && !videoStream.IsCabac) {
|
|
|
|
console.log('Video not CABAC');
|
2015-02-06 20:25:23 -07:00
|
|
|
//return false;
|
2014-10-22 21:26:01 -07:00
|
|
|
}
|
|
|
|
|
2014-10-07 18:37:45 -07:00
|
|
|
if (!videoStream.Width) {
|
|
|
|
console.log('Transcoding because resolution is unknown');
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2014-10-07 18:37:45 -07:00
|
|
|
}
|
|
|
|
|
2014-06-22 09:42:50 -07:00
|
|
|
if (videoStream && videoStream.IsAnamorphic) {
|
|
|
|
console.log('Transcoding because video is anamorphic');
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2014-06-22 09:42:50 -07:00
|
|
|
}
|
|
|
|
|
2014-10-07 18:37:45 -07:00
|
|
|
if (!mediaSource.Bitrate) {
|
|
|
|
console.log('Transcoding because bitrate is unknown');
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2014-10-07 18:37:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mediaSource.Bitrate > bitrate) {
|
2014-01-16 21:53:16 -07:00
|
|
|
console.log('Transcoding because bitrate is too high');
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2014-01-08 13:29:09 -07:00
|
|
|
}
|
2014-06-11 19:38:40 -07:00
|
|
|
|
2014-06-09 12:16:14 -07:00
|
|
|
var extension = (mediaSource.Container || '').toLowerCase();
|
|
|
|
|
2014-08-31 12:15:33 -07:00
|
|
|
var profile = (videoStream ? (videoStream.Profile || '') : '').toLowerCase();
|
|
|
|
|
|
|
|
// only support high, baseline variants and main variants
|
|
|
|
if (isH264 && profile != 'high' && profile.indexOf('baseline') == -1 && profile.indexOf('main') == -1) {
|
2014-10-07 18:37:45 -07:00
|
|
|
console.log('Transcoding because of unsupported h264 profile');
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2014-06-07 12:46:24 -07:00
|
|
|
}
|
2014-01-08 13:29:09 -07:00
|
|
|
|
2015-02-10 20:28:34 -07:00
|
|
|
if (mediaSource.Protocol == 'Http') {
|
|
|
|
if (Dashboard.isConnectMode()) {
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2015-02-10 20:28:34 -07:00
|
|
|
}
|
2015-03-16 21:08:09 -07:00
|
|
|
return 'DirectPlay';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extension == 'mp4') {
|
|
|
|
return 'DirectStream';
|
2015-02-10 20:28:34 -07:00
|
|
|
}
|
|
|
|
|
2014-08-14 06:24:30 -07:00
|
|
|
if (extension == 'm4v' || extension == 'mkv') {
|
2015-03-16 21:08:09 -07:00
|
|
|
if ($.browser.chrome) {
|
|
|
|
return 'DirectStream';
|
|
|
|
}
|
2014-01-10 06:52:01 -07:00
|
|
|
}
|
2014-01-08 13:29:09 -07:00
|
|
|
|
2015-03-16 21:08:09 -07:00
|
|
|
return null;
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
2014-01-08 21:45:09 -07:00
|
|
|
|
2015-03-26 09:58:02 -07:00
|
|
|
self.getFinalVideoParams = function (mediaSource, bitrate, audioStreamIndex, subtitleStreamIndex, transcodingExtension) {
|
2014-01-08 21:45:09 -07:00
|
|
|
|
2014-03-22 09:16:43 -07:00
|
|
|
var mediaStreams = mediaSource.MediaStreams;
|
2014-03-20 20:31:40 -07:00
|
|
|
|
|
|
|
var videoStream = mediaStreams.filter(function (stream) {
|
2014-03-20 01:34:54 -07:00
|
|
|
return stream.Type === "Video";
|
|
|
|
})[0];
|
2014-01-16 21:53:16 -07:00
|
|
|
|
2014-03-20 20:31:40 -07:00
|
|
|
var audioStream = mediaStreams.filter(function (stream) {
|
2014-10-07 18:37:45 -07:00
|
|
|
return stream.Index === audioStreamIndex && stream.Type == 'Audio';
|
2014-03-20 01:34:54 -07:00
|
|
|
})[0];
|
2014-01-16 21:53:16 -07:00
|
|
|
|
2014-03-20 20:31:40 -07:00
|
|
|
var subtitleStream = mediaStreams.filter(function (stream) {
|
2014-10-07 18:37:45 -07:00
|
|
|
return stream.Index === subtitleStreamIndex && stream.Type == 'Subtitle';
|
2014-03-20 01:34:54 -07:00
|
|
|
})[0];
|
2014-01-29 14:54:40 -07:00
|
|
|
|
2015-03-26 09:58:02 -07:00
|
|
|
var directPlayMethod = self.getVideoDirectPlayMethod(mediaSource, videoStream, audioStream, subtitleStream, bitrate);
|
2014-01-08 13:29:09 -07:00
|
|
|
|
2015-02-02 11:14:02 -07:00
|
|
|
var audioBitrate = bitrate >= 700000 ? 192000 : 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-03-27 12:30:21 -07:00
|
|
|
var params = {
|
2015-03-16 21:08:09 -07:00
|
|
|
isStatic: directPlayMethod != null,
|
2014-01-16 21:53:16 -07:00
|
|
|
audioCodec: transcodingExtension == '.webm' ? 'vorbis' : 'aac',
|
|
|
|
videoCodec: transcodingExtension == '.webm' ? 'vpx' : 'h264',
|
|
|
|
audioBitrate: audioBitrate,
|
|
|
|
videoBitrate: videoBitrate
|
|
|
|
};
|
2014-03-29 08:40:32 -07:00
|
|
|
|
2014-03-27 12:30:21 -07:00
|
|
|
if (params.videoCodec == 'h264') {
|
|
|
|
params.profile = 'baseline';
|
|
|
|
params.level = '3';
|
|
|
|
}
|
|
|
|
|
|
|
|
return params;
|
2014-03-20 20:31:40 -07:00
|
|
|
};
|
2014-01-08 13:29:09 -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;
|
|
|
|
|
2014-08-02 19:16:37 -07:00
|
|
|
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"
|
|
|
|
});
|
|
|
|
}
|
2014-08-02 19:16:37 -07:00
|
|
|
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) {
|
2013-05-24 18:51:17 -07:00
|
|
|
|
2014-03-29 08:40:32 -07:00
|
|
|
if (options.items) {
|
2013-05-24 18:51:17 -07:00
|
|
|
|
2014-03-29 12:02:43 -07:00
|
|
|
translateItemsForPlayback(options.items).done(function (items) {
|
2013-07-16 14:55:50 -07:00
|
|
|
|
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(',')
|
2013-05-24 18:51:17 -07:00
|
|
|
|
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) {
|
2013-05-24 18:51:17 -07:00
|
|
|
|
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
|
|
|
});
|
2013-05-24 18:51:17 -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 () {
|
2015-03-13 01:58:50 -07:00
|
|
|
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 () {
|
2015-03-13 01:58:50 -07:00
|
|
|
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
|
|
|
|
2015-03-26 09:58:02 -07:00
|
|
|
var optimalVersion = versions.filter(function (v) {
|
2014-03-20 21:52:46 -07:00
|
|
|
|
2015-03-26 09:58:02 -07:00
|
|
|
v.enableDirectPlay = v.SupportsDirectPlay && v.Protocol == 'Http' && !v.RequiredHttpHeaders.length;
|
2014-03-20 21:52:46 -07:00
|
|
|
|
2015-03-26 09:58:02 -07:00
|
|
|
return v.enableDirectPlay;
|
2015-03-16 21:08:09 -07:00
|
|
|
|
2015-03-26 09:58:02 -07:00
|
|
|
})[0];
|
2015-03-07 22:37:48 -07:00
|
|
|
|
2015-03-26 09:58:02 -07:00
|
|
|
if (!optimalVersion) {
|
2015-03-07 22:37:48 -07:00
|
|
|
optimalVersion = versions.filter(function (v) {
|
|
|
|
|
2015-03-26 09:58:02 -07:00
|
|
|
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-03-26 11:23:46 -07:00
|
|
|
function getPlaybackInfo(itemId, deviceProfile, startPosition) {
|
|
|
|
|
|
|
|
return ApiClient.ajax({
|
|
|
|
url: ApiClient.getUrl('Items/' + itemId + '/PlaybackInfo', {
|
|
|
|
UserId: Dashboard.getCurrentUserId(),
|
|
|
|
StartPositionTicks: startPosition || 0
|
|
|
|
}),
|
|
|
|
type: 'POST',
|
|
|
|
data: JSON.stringify({
|
|
|
|
DeviceProfile: deviceProfile
|
|
|
|
}),
|
|
|
|
contentType: "application/json",
|
|
|
|
dataType: "json"
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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 : '';
|
|
|
|
|
|
|
|
if (type == 'video') {
|
|
|
|
|
|
|
|
contentType = 'video/' + mediaSource.Container;
|
|
|
|
|
|
|
|
if (mediaSource.enableDirectPlay) {
|
|
|
|
mediaUrl = mediaSource.Path;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (mediaSource.SupportsDirectStream) {
|
|
|
|
|
|
|
|
mediaUrl = ApiClient.getUrl('Videos/' + item.Id + '/stream.' + mediaSource.Container, {
|
|
|
|
Static: true,
|
|
|
|
mediaSourceId: mediaSource.Id,
|
|
|
|
api_key: ApiClient.accessToken()
|
|
|
|
});
|
|
|
|
mediaUrl += seekParam;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
startTimeTicksOffset = startPosition || 0;
|
|
|
|
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) {
|
|
|
|
|
|
|
|
mediaUrl = mediaSource.Path;
|
|
|
|
|
|
|
|
} 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;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
contentType = 'audio/' + mediaSource.TranscodingContainer;
|
|
|
|
|
|
|
|
mediaUrl = ApiClient.getUrl(mediaSource.TranscodingUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
startTimeTicksOffset = startPosition || 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
url: mediaUrl,
|
|
|
|
contentType: contentType,
|
|
|
|
startTimeTicksOffset: startTimeTicksOffset,
|
|
|
|
startPositionInSeekParam: startPositionInSeekParam
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-03-03 00:03:17 -07:00
|
|
|
self.playInternal = function (item, startPosition, callback) {
|
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
|
|
|
|
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) {
|
|
|
|
showPlaybackInfoErrorMessage('PlaceHolder');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-03 00:03:17 -07:00
|
|
|
var mediaSource;
|
2015-03-26 09:58:02 -07:00
|
|
|
var deviceProfile = self.getDeviceProfile();
|
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
getPlaybackInfo(item.Id, deviceProfile, startPosition).done(function (result) {
|
2015-03-07 22:37:48 -07:00
|
|
|
|
|
|
|
if (validatePlaybackInfoResult(result)) {
|
2013-04-08 21:16:32 -07:00
|
|
|
|
2015-03-07 22:37:48 -07:00
|
|
|
mediaSource = getOptimalMediaSource(item.MediaType, result.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-07 22:37:48 -07:00
|
|
|
self.currentMediaSource = mediaSource;
|
|
|
|
self.currentItem = item;
|
2014-11-18 19:45:12 -07:00
|
|
|
|
2015-03-07 22:37:48 -07:00
|
|
|
if (item.MediaType === "Video") {
|
2014-11-18 19:45:12 -07:00
|
|
|
|
2015-03-26 09:58:02 -07:00
|
|
|
self.currentMediaElement = self.playVideo(deviceProfile, result, item, self.currentMediaSource, startPosition);
|
2015-03-03 00:03:17 -07:00
|
|
|
self.currentDurationTicks = self.currentMediaSource.RunTimeTicks;
|
|
|
|
|
|
|
|
self.updateNowPlayingInfo(item);
|
|
|
|
|
2015-03-07 22:37:48 -07:00
|
|
|
} else if (item.MediaType === "Audio") {
|
2014-03-20 20:31:40 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
self.currentMediaElement = playAudio(item, self.currentMediaSource, startPosition);
|
2015-03-07 22:37:48 -07:00
|
|
|
self.currentDurationTicks = self.currentMediaSource.RunTimeTicks;
|
|
|
|
}
|
2015-03-03 00:03:17 -07:00
|
|
|
|
2015-03-07 22:37:48 -07:00
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
2015-03-03 00:03:17 -07:00
|
|
|
|
2015-03-07 22:37:48 -07:00
|
|
|
} else {
|
|
|
|
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
|
|
|
});
|
2014-04-11 08:36:25 -07:00
|
|
|
};
|
|
|
|
|
2015-03-03 00:03:17 -07:00
|
|
|
function validatePlaybackInfoResult(result) {
|
|
|
|
|
2015-03-06 20:53:31 -07:00
|
|
|
if (result.ErrorCode) {
|
|
|
|
|
|
|
|
showPlaybackInfoErrorMessage(result.ErrorCode);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-03 00:03:17 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-06 20:53:31 -07:00
|
|
|
function showPlaybackInfoErrorMessage(errorCode) {
|
|
|
|
|
|
|
|
// This timeout is messy, but if jqm is in the act of hiding a popup, it will not show a new one
|
|
|
|
// If we're coming from the popup play menu, this will be a problem
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
Dashboard.alert({
|
|
|
|
message: Globalize.translate('MessagePlaybackError' + errorCode),
|
|
|
|
title: Globalize.translate('HeaderPlaybackError')
|
|
|
|
});
|
|
|
|
}, 300);
|
2015-03-03 00:03:17 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-13 10:27:13 -07:00
|
|
|
self.getNowPlayingNameHtml = function (playerState) {
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
var nowPlayingItem = playerState.NowPlayingItem;
|
|
|
|
var topText = nowPlayingItem.Name;
|
2014-04-13 10:27:13 -07:00
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
if (nowPlayingItem.MediaType == 'Video') {
|
|
|
|
if (nowPlayingItem.IndexNumber != null) {
|
|
|
|
topText = nowPlayingItem.IndexNumber + " - " + topText;
|
2014-04-13 10:27:13 -07:00
|
|
|
}
|
2014-04-22 10:25:54 -07:00
|
|
|
if (nowPlayingItem.ParentIndexNumber != null) {
|
|
|
|
topText = nowPlayingItem.ParentIndexNumber + "." + topText;
|
2014-04-13 10:27:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var bottomText = '';
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
if (nowPlayingItem.Artists && nowPlayingItem.Artists.length) {
|
2014-04-13 10:27:13 -07:00
|
|
|
bottomText = topText;
|
2014-04-22 10:25:54 -07:00
|
|
|
topText = nowPlayingItem.Artists[0];
|
2014-04-13 10:27:13 -07:00
|
|
|
}
|
2014-04-22 10:25:54 -07:00
|
|
|
else if (nowPlayingItem.SeriesName || nowPlayingItem.Album) {
|
2014-04-13 10:27:13 -07:00
|
|
|
bottomText = topText;
|
2014-04-22 10:25:54 -07:00
|
|
|
topText = nowPlayingItem.SeriesName || nowPlayingItem.Album;
|
2014-04-13 10:27:13 -07:00
|
|
|
}
|
2014-04-22 10:25:54 -07:00
|
|
|
else if (nowPlayingItem.ProductionYear) {
|
|
|
|
bottomText = nowPlayingItem.ProductionYear;
|
2014-04-13 10:27:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return bottomText ? topText + '<br/>' + bottomText : topText;
|
|
|
|
};
|
|
|
|
|
|
|
|
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-03-27 19:01:26 -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-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
|
|
|
|
2015-03-03 00:03:17 -07:00
|
|
|
self.playInternal(newItem, 0, function () {
|
2015-03-13 01:58:50 -07:00
|
|
|
self.setPlaylistState(i);
|
2013-06-07 09:06:32 -07:00
|
|
|
});
|
2013-04-30 10:21:21 -07:00
|
|
|
};
|
|
|
|
|
2015-03-13 01:58:50 -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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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) {
|
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 () {
|
2015-03-13 01:58:50 -07:00
|
|
|
self.setPlaylistState(newIndex);
|
2013-07-16 14:55:50 -07:00
|
|
|
});
|
|
|
|
}
|
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) {
|
2015-03-03 00:03:17 -07:00
|
|
|
self.playInternal(newItem, 0, function () {
|
2015-03-13 01:58:50 -07:00
|
|
|
self.setPlaylistState(newIndex);
|
2013-07-18 20:12:52 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
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
|
|
|
};
|
|
|
|
|
2014-03-29 08:40:32 -07:00
|
|
|
self.queue = function (options) {
|
2013-06-07 09:06:32 -07:00
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
if (!self.currentMediaElement) {
|
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
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
if (!self.currentMediaElement) {
|
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
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
self.currentMediaElement.pause();
|
2013-05-23 13:09:01 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
self.unpause = function () {
|
2014-06-23 21:18:02 -07:00
|
|
|
self.currentMediaElement.play();
|
2013-05-23 13:09:01 -07:00
|
|
|
};
|
|
|
|
|
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-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
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.setVolume(0);
|
2013-05-23 13:09:01 -07:00
|
|
|
};
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.unMute = function () {
|
2014-03-08 01:09:45 -07:00
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.setVolume(self.getSavedVolume() * 100);
|
2013-08-27 21:31:34 -07:00
|
|
|
};
|
|
|
|
|
2014-11-13 23:27:10 -07:00
|
|
|
self.volume = function () {
|
2014-10-22 21:26:01 -07:00
|
|
|
return self.currentMediaElement.volume * 100;
|
|
|
|
};
|
|
|
|
|
2013-08-27 21:31:34 -07:00
|
|
|
self.toggleMute = function () {
|
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
if (self.currentMediaElement) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-04-30 20:24:55 -07:00
|
|
|
console.log('MediaPlayer toggling mute');
|
|
|
|
|
2014-10-22 21:26:01 -07:00
|
|
|
if (self.volume()) {
|
2014-04-11 08:36:25 -07:00
|
|
|
self.mute();
|
|
|
|
} else {
|
|
|
|
self.unMute();
|
|
|
|
}
|
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
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
if (self.currentMediaElement) {
|
2014-10-22 21:26:01 -07:00
|
|
|
self.setVolume(Math.max(self.volume() - 2, 0));
|
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
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
if (self.currentMediaElement) {
|
2014-10-22 21:26:01 -07:00
|
|
|
self.setVolume(Math.min(self.volume() + 2, 100));
|
2014-04-11 08:36:25 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Sets volume using a 0-100 scale
|
|
|
|
self.setVolume = function (val) {
|
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
if (self.currentMediaElement) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-04-30 20:24:55 -07:00
|
|
|
console.log('MediaPlayer setting volume to ' + val);
|
2014-06-23 21:18:02 -07:00
|
|
|
self.currentMediaElement.volume = val / 100;
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
self.onVolumeChanged(self.currentMediaElement);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
self.saveVolume();
|
2013-08-27 21:31:34 -07:00
|
|
|
}
|
2013-04-30 10:21:21 -07:00
|
|
|
};
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.saveVolume = function (val) {
|
|
|
|
|
|
|
|
if (val) {
|
2014-07-15 12:16:16 -07:00
|
|
|
store.setItem("volume", val);
|
2014-04-11 08:36:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
self.getSavedVolume = function () {
|
2014-07-15 12:16:16 -07:00
|
|
|
return store.getItem("volume") || 0.5;
|
2014-04-11 08:36:25 -07:00
|
|
|
};
|
|
|
|
|
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"
|
|
|
|
};
|
|
|
|
|
2014-08-02 19:16:37 -07:00
|
|
|
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;
|
|
|
|
|
2014-08-02 19:16:37 -07:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
var elem = self.currentMediaElement;
|
2013-03-31 18:52:07 -07:00
|
|
|
|
2014-07-01 14:13:32 -07:00
|
|
|
if (elem) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
2014-07-01 14:13:32 -07:00
|
|
|
elem.pause();
|
2014-04-12 10:27:53 -07:00
|
|
|
|
2014-07-01 14:13:32 -07:00
|
|
|
$(elem).off("ended.playnext").one("ended", function () {
|
2013-06-07 10:23:23 -07:00
|
|
|
|
2014-07-01 14:13:32 -07:00
|
|
|
$(this).off();
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-07-01 14:13:32 -07:00
|
|
|
if (this.tagName.toLowerCase() != 'audio') {
|
|
|
|
$(this).remove();
|
|
|
|
}
|
|
|
|
|
2014-07-17 15:21:35 -07:00
|
|
|
elem.src = null;
|
2014-07-01 14:13:32 -07:00
|
|
|
elem.src = "";
|
|
|
|
self.currentMediaElement = null;
|
|
|
|
self.currentItem = null;
|
|
|
|
self.currentMediaSource = null;
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-07-21 18:29:06 -07:00
|
|
|
// When the browser regains focus it may start auto-playing the last video
|
|
|
|
if ($.browser.safari) {
|
|
|
|
elem.src = 'files/dummy.mp4';
|
|
|
|
elem.play();
|
|
|
|
}
|
|
|
|
|
2014-07-01 14:13:32 -07:00
|
|
|
}).trigger("ended");
|
|
|
|
|
|
|
|
} else {
|
2014-06-23 21:18:02 -07:00
|
|
|
self.currentMediaElement = 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
|
|
|
|
2014-07-01 14:13:32 -07:00
|
|
|
if (self.currentItem && self.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();
|
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 () {
|
2014-06-23 21:18:02 -07:00
|
|
|
return self.currentMediaElement != null;
|
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 () {
|
2014-04-12 10:27:53 -07:00
|
|
|
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
var result = self.getPlayerStateInternal(self.currentMediaElement, self.currentItem, self.currentMediaSource);
|
2014-04-12 10:27:53 -07:00
|
|
|
|
|
|
|
deferred.resolveWith(null, [result]);
|
|
|
|
|
|
|
|
return deferred.promise();
|
|
|
|
};
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-04-12 10:27:53 -07:00
|
|
|
self.getPlayerStateInternal = function (playerElement, item, mediaSource) {
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
var state = {
|
|
|
|
PlayState: {}
|
|
|
|
};
|
2014-04-12 10:27:53 -07:00
|
|
|
|
|
|
|
if (playerElement) {
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
state.PlayState.VolumeLevel = playerElement.volume * 100;
|
|
|
|
state.PlayState.IsMuted = playerElement.volume == 0;
|
|
|
|
state.PlayState.IsPaused = playerElement.paused;
|
|
|
|
state.PlayState.PositionTicks = self.getCurrentTicks(playerElement);
|
|
|
|
|
|
|
|
var currentSrc = playerElement.currentSrc;
|
|
|
|
|
|
|
|
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';
|
|
|
|
}
|
2014-04-12 10:27:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mediaSource) {
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
state.PlayState.MediaSourceId = mediaSource.Id;
|
|
|
|
|
|
|
|
state.NowPlayingItem = {
|
|
|
|
RunTimeTicks: mediaSource.RunTimeTicks
|
|
|
|
};
|
2014-04-12 10:27:53 -07:00
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
state.PlayState.CanSeek = mediaSource.RunTimeTicks && mediaSource.RunTimeTicks > 0;
|
2014-04-12 10:27:53 -07:00
|
|
|
}
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
if (item) {
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
state.NowPlayingItem = state.NowPlayingItem || {};
|
|
|
|
var nowPlayingItem = state.NowPlayingItem;
|
2014-04-27 18:57:29 -07:00
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
nowPlayingItem.Id = item.Id;
|
|
|
|
nowPlayingItem.MediaType = item.MediaType;
|
|
|
|
nowPlayingItem.Type = item.Type;
|
|
|
|
nowPlayingItem.Name = item.Name;
|
|
|
|
|
|
|
|
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-03-20 01:34:54 -07:00
|
|
|
|
2014-04-12 10:27:53 -07:00
|
|
|
var imageTags = item.ImageTags || {};
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-06-28 12:35:30 -07:00
|
|
|
if (item.SeriesPrimaryImageTag) {
|
|
|
|
|
|
|
|
nowPlayingItem.PrimaryImageItemId = item.SeriesId;
|
|
|
|
nowPlayingItem.PrimaryImageTag = item.SeriesPrimaryImageTag;
|
|
|
|
}
|
|
|
|
else if (imageTags.Primary) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
nowPlayingItem.PrimaryImageItemId = item.Id;
|
|
|
|
nowPlayingItem.PrimaryImageTag = imageTags.Primary;
|
2014-04-12 10:27:53 -07:00
|
|
|
}
|
2014-04-13 10:27:13 -07:00
|
|
|
else if (item.AlbumPrimaryImageTag) {
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
nowPlayingItem.PrimaryImageItemId = item.AlbumId;
|
|
|
|
nowPlayingItem.PrimaryImageTag = item.AlbumPrimaryImageTag;
|
2014-04-13 10:27:13 -07:00
|
|
|
}
|
|
|
|
else if (item.SeriesPrimaryImageTag) {
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
nowPlayingItem.PrimaryImageItemId = item.SeriesId;
|
|
|
|
nowPlayingItem.PrimaryImageTag = item.SeriesPrimaryImageTag;
|
2014-04-13 10:27:13 -07:00
|
|
|
}
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-04-12 10:27:53 -07:00
|
|
|
if (item.BackdropImageTags && item.BackdropImageTags.length) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
nowPlayingItem.BackdropItemId = item.Id;
|
|
|
|
nowPlayingItem.BackdropImageTag = item.BackdropImageTags[0];
|
2014-04-12 10:27:53 -07:00
|
|
|
}
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-04-12 10:27:53 -07:00
|
|
|
if (imageTags.Thumb) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
nowPlayingItem.ThumbItemId = item.Id;
|
|
|
|
nowPlayingItem.ThumbImageTag = imageTags.Thumb;
|
2014-04-12 10:27:53 -07:00
|
|
|
}
|
2014-06-28 12:35:30 -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;
|
|
|
|
}
|
2014-04-11 08:36:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
|
|
|
|
2014-04-12 10:27:53 -07:00
|
|
|
self.beginPlayerUpdates = function () {
|
|
|
|
// Nothing to setup here
|
|
|
|
};
|
|
|
|
|
|
|
|
self.endPlayerUpdates = function () {
|
|
|
|
// Nothing to setup here
|
|
|
|
};
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.onPlaybackStart = function (playerElement, item, mediaSource) {
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.updateCanClientSeek(playerElement);
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-04-12 10:27:53 -07:00
|
|
|
var state = self.getPlayerStateInternal(playerElement, item, mediaSource);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
$(self).trigger('playbackstart', [state]);
|
2014-04-22 17:50:47 -07:00
|
|
|
|
2014-05-07 11:38:50 -07:00
|
|
|
self.startProgressInterval();
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.onVolumeChanged = function (playerElement) {
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.saveVolume(playerElement.volume);
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-06-11 12:31:33 -07:00
|
|
|
var state = self.getPlayerStateInternal(playerElement, self.currentItem, self.currentMediaSource);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
$(self).trigger('volumechange', [state]);
|
|
|
|
};
|
|
|
|
|
2014-08-14 06:24:30 -07:00
|
|
|
self.cleanup = function () {
|
2014-08-10 15:13:17 -07:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-04-11 08:36:25 -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');
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
var playerElement = this;
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2015-03-20 10:29:18 -07:00
|
|
|
var currentStreamId = getParameterByName('StreamId', playerElement.currentSrc);
|
|
|
|
|
2014-06-21 22:52:31 -07:00
|
|
|
$(playerElement).off('.mediaplayerevent').off('ended.playbackstopped');
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
self.cleanup(playerElement);
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
clearProgressInterval();
|
|
|
|
|
2014-06-11 12:31:33 -07:00
|
|
|
var item = self.currentItem;
|
|
|
|
var mediaSource = self.currentMediaSource;
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
if (item.MediaType == "Video") {
|
2015-03-20 10:29:18 -07:00
|
|
|
|
|
|
|
ApiClient.stopActiveEncodings(currentStreamId);
|
2014-04-11 08:36:25 -07:00
|
|
|
if (self.isFullScreen()) {
|
|
|
|
self.exitFullScreen();
|
|
|
|
}
|
|
|
|
self.resetEnhancements();
|
2014-03-20 01:34:54 -07:00
|
|
|
}
|
|
|
|
|
2014-04-12 10:27:53 -07:00
|
|
|
var state = self.getPlayerStateInternal(playerElement, item, mediaSource);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
$(self).trigger('playbackstop', [state]);
|
|
|
|
};
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.onPlaystateChange = function (playerElement) {
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-06-11 12:31:33 -07:00
|
|
|
var state = self.getPlayerStateInternal(playerElement, self.currentItem, self.currentMediaSource);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
$(self).trigger('playstatechange', [state]);
|
|
|
|
};
|
|
|
|
|
2014-07-04 22:21:13 -07:00
|
|
|
$(window).on("beforeunload", function () {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
// Try to report playback stopped before the browser closes
|
2014-06-23 21:18:02 -07:00
|
|
|
if (self.currentItem && self.currentMediaElement && currentProgressInterval) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
self.onPlaybackStopped.call(self.currentMediaElement);
|
2014-04-11 08:36:25 -07:00
|
|
|
}
|
|
|
|
});
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-05-07 11:38:50 -07:00
|
|
|
function sendProgressUpdate() {
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
var state = self.getPlayerStateInternal(self.currentMediaElement, 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
|
|
|
}
|
2014-03-20 01:34:54 -07:00
|
|
|
|
|
|
|
function clearProgressInterval() {
|
|
|
|
|
|
|
|
if (currentProgressInterval) {
|
|
|
|
clearTimeout(currentProgressInterval);
|
|
|
|
currentProgressInterval = null;
|
|
|
|
}
|
2014-04-30 08:07:02 -07:00
|
|
|
}
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-09-05 20:56:55 -07:00
|
|
|
self.canPlayWebm = function () {
|
2014-03-20 01:34:54 -07:00
|
|
|
|
|
|
|
return testableVideoElement.canPlayType('video/webm').replace(/no/, '');
|
2014-08-14 06:24:30 -07:00
|
|
|
};
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-04-14 20:54:52 -07:00
|
|
|
self.canAutoPlayAudio = function () {
|
|
|
|
|
|
|
|
if ($.browser.android || ($.browser.webkit && !$.browser.chrome)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
function getAudioElement() {
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
var elem = $('.mediaPlayerAudio');
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
if (elem.length) {
|
|
|
|
return elem;
|
|
|
|
}
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
var html = '';
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-04-14 20:54:52 -07:00
|
|
|
var requiresControls = !self.canAutoPlayAudio();
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
if (requiresControls) {
|
|
|
|
html += '<div class="mediaPlayerAudioContainer"><div class="mediaPlayerAudioContainerInner">';;
|
|
|
|
} else {
|
|
|
|
html += '<div class="mediaPlayerAudioContainer" style="display:none;"><div class="mediaPlayerAudioContainerInner">';;
|
|
|
|
}
|
|
|
|
|
2014-04-13 11:25:22 -07:00
|
|
|
html += '<audio class="mediaPlayerAudio" controls>';
|
2014-04-11 08:36:25 -07:00
|
|
|
html += '</audio></div></div>';
|
|
|
|
|
|
|
|
$(document.body).append(html);
|
|
|
|
|
|
|
|
return $('.mediaPlayerAudio');
|
2014-04-02 14:55:19 -07:00
|
|
|
}
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2015-03-26 11:23:46 -07:00
|
|
|
function playAudio(item, mediaSource, startPositionTicks) {
|
2015-03-07 22:37:48 -07:00
|
|
|
|
2015-03-26 11:23:46 -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
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
var initialVolume = self.getSavedVolume();
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
return getAudioElement().each(function () {
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-04-13 10:27:13 -07:00
|
|
|
this.src = audioUrl;
|
2014-03-20 01:34:54 -07:00
|
|
|
this.volume = initialVolume;
|
2014-04-11 08:36:25 -07:00
|
|
|
this.play();
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-06-21 22:52:31 -07:00
|
|
|
}).on("volumechange.mediaplayerevent", function () {
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
console.log('audio element event: volumechange');
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.onVolumeChanged(this);
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-06-21 22:52:31 -07:00
|
|
|
}).one("playing.mediaplayerevent", function () {
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
console.log('audio element event: playing');
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
$('.mediaPlayerAudioContainer').hide();
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
// 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);
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.onPlaybackStart(this, item, mediaSource);
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-06-21 22:52:31 -07:00
|
|
|
}).on("pause.mediaplayerevent", function () {
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
console.log('audio element event: pause');
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.onPlaystateChange(this);
|
2014-03-20 01:34:54 -07:00
|
|
|
|
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-03-20 01:34:54 -07:00
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
console.log('audio element event: playing');
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.onPlaystateChange(this);
|
2014-03-20 01:34:54 -07:00
|
|
|
|
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("timeupdate.mediaplayerevent", function () {
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
self.setCurrentTime(self.getCurrentTicks(this));
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
})[0];
|
2014-03-20 01:34:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
function canPlayAudioStreamDirect(audioStream) {
|
|
|
|
|
|
|
|
var audioCodec = (audioStream.Codec || '').toLowerCase().replace('-', '');
|
|
|
|
|
|
|
|
if (audioCodec.indexOf('aac') == -1 &&
|
|
|
|
audioCodec.indexOf('mp3') == -1 &&
|
|
|
|
audioCodec.indexOf('mpeg') == -1) {
|
|
|
|
|
2014-10-07 18:37:45 -07:00
|
|
|
console.log('Cannot direct play. Unsupported audio codec');
|
|
|
|
|
2014-03-20 01:34:54 -07:00
|
|
|
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;
|
2014-04-11 08:36:25 -07:00
|
|
|
}
|
2014-03-20 01:34:54 -07:00
|
|
|
|
2014-03-22 09:16:43 -07:00
|
|
|
var getItemFields = "MediaSources,Chapters";
|
2014-04-05 10:01:04 -07:00
|
|
|
|
2014-04-06 19:06:09 -07:00
|
|
|
self.getCurrentTargetInfo = function () {
|
2014-04-05 10:01:04 -07:00
|
|
|
return self.getTargets()[0];
|
|
|
|
};
|
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
|
|
|
|
2014-03-29 08:40:32 -07:00
|
|
|
window.MediaController.registerPlayer(window.MediaPlayer);
|
2014-04-05 10:01:04 -07:00
|
|
|
window.MediaController.setActivePlayer(window.MediaPlayer);
|
2014-03-29 08:40:32 -07:00
|
|
|
|
|
|
|
|
2014-07-15 12:16:16 -07:00
|
|
|
})(document, setTimeout, clearTimeout, screen, window.store, $, setInterval, window);
|