jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/playmenu.js

117 lines
3.7 KiB
JavaScript
Raw Normal View History

2016-07-21 13:25:55 -07:00
define(['actionsheet', 'datetime', 'playbackManager', 'globalize', 'appSettings'], function (actionsheet, datetime, playbackManager, globalize, appSettings) {
var isMobileApp = window.Dashboard != null;
2016-07-17 13:08:04 -07:00
function show(options) {
var item = options.item;
var itemType = item.Type;
var mediaType = item.MediaType;
var isFolder = item.IsFolder;
var itemId = item.Id;
2016-07-23 11:10:22 -07:00
var channelId = item.ChannelId;
2016-07-17 13:08:04 -07:00
var serverId = item.ServerId;
var resumePositionTicks = item.UserData ? item.UserData.PlaybackPositionTicks : null;
2016-07-21 13:25:55 -07:00
var showExternalPlayer = isMobileApp && mediaType == 'Video' && !isFolder && appSettings.enableExternalPlayers();
2016-07-23 11:10:22 -07:00
var playableItemId = itemType == 'Program' ? channelId : itemId;
2016-07-21 13:25:55 -07:00
if (!resumePositionTicks && mediaType != "Audio" && !isFolder && !showExternalPlayer) {
2016-07-28 19:42:42 -07:00
playbackManager.play({
ids: [playableItemId],
serverId: serverId
});
2016-07-17 13:08:04 -07:00
return;
}
var menuItems = [];
if (resumePositionTicks) {
menuItems.push({
name: globalize.translate('sharedcomponents#ResumeAt', datetime.getDisplayRunningTime(resumePositionTicks)),
id: 'resume'
});
menuItems.push({
name: globalize.translate('sharedcomponents#PlayFromBeginning'),
id: 'play'
});
} else {
menuItems.push({
name: globalize.translate('sharedcomponents#Play'),
id: 'play'
});
}
2016-07-21 13:25:55 -07:00
if (showExternalPlayer) {
menuItems.push({
name: globalize.translate('ButtonPlayExternalPlayer'),
id: 'externalplayer'
});
}
2016-08-06 19:11:39 -07:00
if (playbackManager.canQueue(item)) {
2016-07-17 13:08:04 -07:00
menuItems.push({
name: globalize.translate('sharedcomponents#Queue'),
id: 'queue'
});
}
if (itemType == "Audio" || itemType == "MusicAlbum" || itemType == "MusicArtist" || itemType == "MusicGenre") {
menuItems.push({
name: globalize.translate('sharedcomponents#InstantMix'),
id: 'instantmix'
});
}
if (isFolder || itemType == "MusicArtist" || itemType == "MusicGenre") {
menuItems.push({
name: globalize.translate('sharedcomponents#Shuffle'),
id: 'shuffle'
});
}
actionsheet.show({
items: menuItems,
positionTo: options.positionTo
}).then(function (id) {
switch (id) {
case 'play':
playbackManager.play({
2016-07-23 11:10:22 -07:00
ids: [playableItemId],
serverId: serverId
2016-07-17 13:08:04 -07:00
});
break;
2016-07-21 13:25:55 -07:00
case 'externalplayer':
2016-07-23 11:10:22 -07:00
LibraryBrowser.playInExternalPlayer(playableItemId);
2016-07-21 13:25:55 -07:00
break;
2016-07-17 13:08:04 -07:00
case 'resume':
playbackManager.play({
2016-07-23 11:10:22 -07:00
ids: [playableItemId],
2016-07-17 13:08:04 -07:00
startPositionTicks: resumePositionTicks,
2016-07-23 11:10:22 -07:00
serverId: serverId
2016-07-17 13:08:04 -07:00
});
break;
case 'queue':
playbackManager.queue(item);
break;
case 'instantmix':
playbackManager.instantMix(item);
break;
case 'shuffle':
playbackManager.shuffle(item);
break;
default:
break;
}
});
}
return {
show: show
};
});