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

399 lines
12 KiB
JavaScript
Raw Normal View History

2016-06-13 12:02:48 -07:00
define(['appSettings', 'datetime', 'jQuery', 'emby-slider', 'emby-button'], function (appSettings, datetime, $) {
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
function getDeviceProfile(serverAddress, deviceId, item, startPositionTicks, maxBitrate, mediaSourceId, audioStreamIndex, subtitleStreamIndex) {
2014-09-15 20:33:30 -07:00
2016-02-29 23:02:03 -07:00
var bitrateSetting = appSettings.maxStreamingBitrate();
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
var profile = {};
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
profile.MaxStreamingBitrate = bitrateSetting;
2016-02-22 10:20:38 -07:00
profile.MaxStaticBitrate = 100000000;
profile.MusicStreamingTranscodingBitrate = 192000;
2014-09-16 20:04:10 -07:00
2015-05-25 10:32:22 -07:00
profile.DirectPlayProfiles = [];
2014-09-16 20:04:10 -07:00
2015-05-25 10:32:22 -07:00
profile.DirectPlayProfiles.push({
2016-02-22 10:20:38 -07:00
Container: 'm4v,3gp,ts,mpegts,mov,xvid,vob,mkv,wmv,asf,ogm,ogv,m2v,avi,mpg,mpeg,mp4,webm,wtv,dvr-ms',
2015-05-25 10:32:22 -07:00
Type: 'Video'
});
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
profile.DirectPlayProfiles.push({
2016-02-22 10:20:38 -07:00
Container: 'aac,mp3,mpa,wav,wma,mp2,ogg,oga,webma,ape,opus,flac',
2015-05-25 10:32:22 -07:00
Type: 'Audio'
});
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
profile.TranscodingProfiles = [];
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
profile.TranscodingProfiles.push({
2016-02-22 10:20:38 -07:00
Container: 'mkv',
2015-05-25 10:32:22 -07:00
Type: 'Video',
2016-02-22 10:20:38 -07:00
AudioCodec: 'aac,mp3,ac3',
2015-05-25 10:32:22 -07:00
VideoCodec: 'h264',
2016-02-22 10:20:38 -07:00
Context: 'Streaming'
2015-05-25 10:32:22 -07:00
});
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
profile.TranscodingProfiles.push({
2016-02-22 10:20:38 -07:00
Container: 'mp3',
2015-05-25 10:32:22 -07:00
Type: 'Audio',
2016-02-22 10:20:38 -07:00
AudioCodec: 'mp3',
2015-05-25 10:32:22 -07:00
Context: 'Streaming',
2016-02-22 10:20:38 -07:00
Protocol: 'http'
2015-05-25 10:32:22 -07:00
});
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
profile.ContainerProfiles = [];
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
profile.CodecProfiles = [];
2014-09-16 20:04:10 -07:00
2015-05-25 10:32:22 -07:00
// Subtitle profiles
2016-02-22 10:20:38 -07:00
// External vtt or burn in
2015-05-25 10:32:22 -07:00
profile.SubtitleProfiles = [];
2015-12-14 08:43:03 -07:00
profile.SubtitleProfiles.push({
Format: 'srt',
Method: 'Embed'
});
profile.SubtitleProfiles.push({
Format: 'subrip',
Method: 'Embed'
});
profile.SubtitleProfiles.push({
Format: 'ass',
Method: 'Embed'
});
profile.SubtitleProfiles.push({
Format: 'ssa',
Method: 'Embed'
});
profile.SubtitleProfiles.push({
Format: 'pgs',
Method: 'Embed'
});
profile.SubtitleProfiles.push({
Format: 'pgssub',
Method: 'Embed'
});
profile.SubtitleProfiles.push({
Format: 'dvdsub',
Method: 'Embed'
});
profile.SubtitleProfiles.push({
Format: 'vtt',
Method: 'Embed'
});
profile.SubtitleProfiles.push({
Format: 'sub',
Method: 'Embed'
});
profile.SubtitleProfiles.push({
Format: 'idx',
Method: 'Embed'
});
2016-02-22 10:20:38 -07:00
profile.SubtitleProfiles.push({
Format: 'smi',
Method: 'Embed'
});
2015-12-14 08:43:03 -07:00
2015-05-25 10:32:22 -07:00
profile.ResponseProfiles = [];
2014-09-16 18:38:50 -07:00
2015-05-25 10:32:22 -07:00
return profile;
2014-09-15 20:33:30 -07:00
}
2015-05-25 10:32:22 -07:00
var currentMediaSource;
var currentItem;
var basePlayerState;
var progressInterval;
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
function getVideoStreamInfo(item) {
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
var deviceProfile = getDeviceProfile();
var startPosition = 0;
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
return new Promise(function (resolve, reject) {
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
MediaPlayer.tryStartPlayback(deviceProfile, item, startPosition, function (mediaSource) {
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
playInternalPostMediaSourceSelection(item, mediaSource, startPosition).then(resolve);
});
});
2015-05-25 10:32:22 -07:00
}
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
function playInternalPostMediaSourceSelection(item, mediaSource, startPosition) {
2014-09-15 20:33:30 -07:00
2015-12-14 08:43:03 -07:00
Dashboard.hideLoadingMsg();
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
currentItem = item;
currentMediaSource = mediaSource;
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
basePlayerState = {
PlayState: {
2014-09-15 20:33:30 -07:00
}
2015-05-25 10:32:22 -07:00
};
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
return MediaPlayer.createStreamInfo('Video', item, mediaSource, startPosition).then(function (streamInfo) {
2014-09-15 20:33:30 -07:00
2015-09-21 08:43:10 -07:00
var currentSrc = streamInfo.url;
2014-09-15 20:33:30 -07:00
2015-09-21 08:43:10 -07:00
var audioStreamIndex = getParameterByName('AudioStreamIndex', currentSrc);
2014-09-15 20:33:30 -07:00
2015-09-21 08:43:10 -07:00
if (audioStreamIndex) {
basePlayerState.PlayState.AudioStreamIndex = parseInt(audioStreamIndex);
}
basePlayerState.PlayState.SubtitleStreamIndex = self.currentSubtitleStreamIndex;
basePlayerState.PlayState.PlayMethod = getParameterByName('static', currentSrc) == 'true' ?
'DirectStream' :
'Transcode';
2014-09-15 20:33:30 -07:00
2015-09-21 08:43:10 -07:00
basePlayerState.PlayState.LiveStreamId = getParameterByName('LiveStreamId', currentSrc);
basePlayerState.PlayState.PlaySessionId = getParameterByName('PlaySessionId', currentSrc);
2014-09-15 20:33:30 -07:00
2015-09-21 08:43:10 -07:00
basePlayerState.PlayState.MediaSourceId = mediaSource.Id;
basePlayerState.PlayState.CanSeek = false;
basePlayerState.NowPlayingItem = MediaPlayer.getNowPlayingItemForReporting(item, mediaSource);
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
return streamInfo;
2015-09-21 08:43:10 -07:00
});
2014-09-15 20:33:30 -07:00
}
2015-05-25 10:32:22 -07:00
function getPlayerState(positionTicks) {
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
var state = basePlayerState;
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
state.PlayState.PositionTicks = Math.round(positionTicks);
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
return state;
2014-09-15 20:33:30 -07:00
}
2015-05-25 10:32:22 -07:00
function onPlaybackStart() {
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
var state = getPlayerState();
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
var info = {
ItemId: state.NowPlayingItem.Id,
NowPlayingItem: state.NowPlayingItem
};
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
info = $.extend(info, state.PlayState);
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
ApiClient.reportPlaybackStart(info);
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
// This is really just a ping to let the server know we're still playing
progressInterval = setInterval(function () {
onPlaybackProgress(null);
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
}, 10000);
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
showPostPlayMenu(currentItem);
2015-05-25 10:32:22 -07:00
}
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
function onPlaybackProgress(positionTicks) {
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
var state = getPlayerState(positionTicks);
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
var info = {
ItemId: state.NowPlayingItem.Id,
NowPlayingItem: state.NowPlayingItem
};
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
info = $.extend(info, state.PlayState);
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
ApiClient.reportPlaybackProgress(info);
}
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
function onPlaybackStopped(positionTicks) {
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
var state = getPlayerState(positionTicks);
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
var stopInfo = {
2016-02-26 22:43:12 -07:00
ItemId: state.NowPlayingItem.Id,
MediaSourceId: state.PlayState.MediaSourceId,
PositionTicks: state.PlayState.PositionTicks
2015-05-25 10:32:22 -07:00
};
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
if (state.PlayState.LiveStreamId) {
stopInfo.LiveStreamId = state.PlayState.LiveStreamId;
2014-09-15 20:33:30 -07:00
}
2015-05-25 10:32:22 -07:00
if (state.PlayState.PlaySessionId) {
stopInfo.PlaySessionId = state.PlayState.PlaySessionId;
}
2014-09-15 20:33:30 -07:00
2015-05-25 10:32:22 -07:00
if (progressInterval) {
clearInterval(progressInterval);
progressInterval = null;
}
2016-02-26 22:43:12 -07:00
// Make sure this is after progress reports have stopped
setTimeout(function () {
ApiClient.reportPlaybackStopped(stopInfo);
}, 1000);
2014-09-15 20:33:30 -07:00
}
2015-05-25 10:32:22 -07:00
function showPostPlayMenu(item) {
2014-09-15 20:33:30 -07:00
2015-09-04 09:20:54 -07:00
require(['jqmpopup', 'jqmlistview'], function () {
2015-08-31 21:15:10 -07:00
$('.externalPlayerPostPlayFlyout').popup("close").remove();
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
var html = '<div data-role="popup" class="externalPlayerPostPlayFlyout" data-history="false" data-theme="a" data-dismissible="false">';
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
html += '<ul data-role="listview" style="min-width: 220px;">';
html += '<li data-role="list-divider" style="padding: 1em;text-align:center;">' + Globalize.translate('HeaderExternalPlayerPlayback') + '</li>';
html += '</ul>';
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
html += '<div style="padding:1.5em;">';
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
var autoMarkWatched = item.RunTimeTicks;
2014-09-16 18:38:50 -07:00
2015-08-31 21:15:10 -07:00
if (item.RunTimeTicks && item.RunTimeTicks >= 3000000000) {
2014-09-16 18:38:50 -07:00
2015-08-31 21:15:10 -07:00
autoMarkWatched = false;
2014-09-16 18:38:50 -07:00
2016-02-26 22:43:12 -07:00
html += '<label for="selectMarkAs" class="selectLabel">' + Globalize.translate('LabelMarkAs') + '</label>';
html += '<select id="selectMarkAs">';
html += '<option value="0">' + Globalize.translate('OptionWatched') + '</option>';
html += '<option value="1">' + Globalize.translate('OptionUnwatched') + '</option>';
html += '<option value="2">' + Globalize.translate('OptionInProgress') + '</option>';
html += '</select>';
2014-09-16 18:38:50 -07:00
2015-08-31 21:15:10 -07:00
html += '<br/>';
2014-09-16 18:38:50 -07:00
2016-02-26 22:43:12 -07:00
html += '<div class="fldResumePoint hide">';
2015-08-31 21:15:10 -07:00
html += '<p style="margin-top: 0;">' + Globalize.translate('LabelResumePoint') + '</p>';
2014-09-16 18:38:50 -07:00
2016-06-13 12:02:48 -07:00
html += '<div class="sliderContainer">';
html += '<input type="range" is="emby-slider" pin step=".001" min="0" max="100" value="0" class="playstateSlider"/>';
html += '</div>';
2015-08-31 21:15:10 -07:00
html += '<div class="sliderValue" style="text-align:center;margin:2px 0 4px;">0:00:00</div>';
2016-02-26 22:43:12 -07:00
html += '</div>';
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
html += '<br/>';
}
2014-09-15 20:33:30 -07:00
2016-06-04 20:50:07 -07:00
html += '<button is="emby-button" type="button" class="block submit btnDone" raised>' + Globalize.translate('ButtonImDone') + '</button>';
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
html += '</div>';
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
html += '</div>';
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
$(document.body).append(html);
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
var elem = $('.externalPlayerPostPlayFlyout').popup({}).trigger('create').popup("open").on("popupafterclose", function () {
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
$(this).off("popupafterclose").remove();
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
})[0];
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
$('#selectMarkAs', elem).on('change', function () {
2014-09-16 18:38:50 -07:00
2016-02-26 22:43:12 -07:00
if (this.value == '2') {
2014-09-16 18:38:50 -07:00
2016-02-26 22:43:12 -07:00
elem.querySelector('.fldResumePoint').classList.remove('hide');
2014-09-16 18:38:50 -07:00
2015-08-31 21:15:10 -07:00
} else {
2016-02-26 22:43:12 -07:00
elem.querySelector('.fldResumePoint').classList.add('hide');
2015-08-31 21:15:10 -07:00
}
2014-09-16 18:38:50 -07:00
2015-08-31 21:15:10 -07:00
}).trigger('change');
2014-09-16 18:38:50 -07:00
2015-08-31 21:15:10 -07:00
$('.btnDone', elem).on('click', function () {
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
var position = 0;
2016-02-26 22:43:12 -07:00
var playstateOption = $('#selectMarkAs', elem).val();
if (playstateOption == '2') {
2014-09-16 18:38:50 -07:00
2015-08-31 21:15:10 -07:00
var pct = $(".playstateSlider", elem).val();
var ticks = item.RunTimeTicks * (Number(pct) * .01);
2014-09-16 18:38:50 -07:00
2015-08-31 21:15:10 -07:00
position = ticks;
}
2016-02-26 22:43:12 -07:00
else if (autoMarkWatched || playstateOption == '0') {
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
position = currentMediaSource.RunTimeTicks;
}
2016-02-26 22:43:12 -07:00
else if (playstateOption == '1') {
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
position = 0;
}
onPlaybackStopped(position);
2016-02-26 22:43:12 -07:00
$('.externalPlayerPostPlayFlyout').popup("close").remove();
2015-08-31 21:15:10 -07:00
});
2014-09-15 20:33:30 -07:00
2015-08-31 21:15:10 -07:00
$(".playstateSlider", elem).on("change", function (e) {
2014-09-16 18:38:50 -07:00
2015-08-31 21:15:10 -07:00
var pct = $(this).val();
2014-09-16 18:38:50 -07:00
2015-08-31 21:15:10 -07:00
var time = item.RunTimeTicks * (Number(pct) * .01);
2014-09-16 18:38:50 -07:00
2016-05-05 20:09:36 -07:00
var tooltext = datetime.getDisplayRunningTime(time);
2014-09-16 18:38:50 -07:00
2015-08-31 21:15:10 -07:00
$('.sliderValue', elem).html(tooltext);
2014-09-16 18:38:50 -07:00
2015-12-23 10:46:01 -07:00
console.log("slidin", pct, self.currentDurationTicks, time);
2014-09-16 18:38:50 -07:00
2015-08-31 21:15:10 -07:00
});
2014-09-16 18:38:50 -07:00
});
2014-09-15 20:33:30 -07:00
}
2015-05-25 10:32:22 -07:00
function showMenuForItem(item, players) {
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
require(['actionsheet'], function (actionsheet) {
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
actionsheet.show({
items: players,
callback: function (id) {
var player = players.filter(function (p) {
return p.id == id;
})[0];
2014-09-15 20:33:30 -07:00
2016-02-26 22:43:12 -07:00
if (player) {
window.open(player.url, '_blank');
onPlaybackStart();
}
}
2015-08-31 21:15:10 -07:00
});
2014-09-15 20:33:30 -07:00
});
}
function showPlayMenu(itemId) {
var userId = Dashboard.getCurrentUserId();
2015-12-14 08:43:03 -07:00
ApiClient.getItem(userId, itemId).then(function (item) {
2014-09-15 20:33:30 -07:00
2015-12-14 08:43:03 -07:00
getVideoStreamInfo(item).then(function (streamInfo) {
2015-05-25 10:32:22 -07:00
setTimeout(function () {
ExternalPlayer.showPlayerSelectionMenu(item, streamInfo.url, streamInfo.mimeType);
}, 500);
});
});
}
function getExternalPlayers(url, mimeType) {
var players = [
2016-02-26 22:43:12 -07:00
{
name: 'Vlc', url: 'vlc://' + url, id: 'vlc',
ironIcon: 'airplay'
}
2015-05-25 10:32:22 -07:00
];
2016-02-26 21:39:11 -07:00
return Promise.resolve(players);
2015-05-25 10:32:22 -07:00
}
function showPlayerSelectionMenu(item, url, mimeType) {
2014-09-15 20:33:30 -07:00
2015-12-14 08:43:03 -07:00
ExternalPlayer.getExternalPlayers(url, mimeType).then(function (players) {
2015-05-25 10:32:22 -07:00
showMenuForItem(item, players);
2014-09-15 20:33:30 -07:00
});
}
window.ExternalPlayer = {
2015-05-25 10:32:22 -07:00
showMenu: showPlayMenu,
onPlaybackStart: onPlaybackStart,
2014-09-15 20:33:30 -07:00
getExternalPlayers: getExternalPlayers,
2015-05-25 10:32:22 -07:00
showPlayerSelectionMenu: showPlayerSelectionMenu
2014-09-15 20:33:30 -07:00
};
2016-02-26 22:43:12 -07:00
});