1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/thememediaplayer.js

101 lines
2.8 KiB
JavaScript
Raw Normal View History

2016-09-09 15:03:03 -04:00
define(['playbackManager', 'userSettings'], function (playbackManager, userSettings) {
2016-10-18 01:06:48 -04:00
'use strict';
2016-08-20 17:58:28 -04:00
var currentOwnerId;
var currentThemeIds = [];
function playThemeMedia(items, ownerId) {
2016-12-15 22:39:51 -05:00
var currentThemeItems = items.filter(function (i) {
return enabled(i.MediaType);
});
if (currentThemeItems.length) {
2016-08-20 17:58:28 -04:00
// Stop if a theme song from another ownerId
// Leave it alone if anything else (e.g user playing a movie)
if (!currentOwnerId && playbackManager.isPlaying()) {
return;
}
2016-12-15 22:39:51 -05:00
currentThemeIds = currentThemeItems.map(function (i) {
2016-12-02 15:10:35 -05:00
return i.Id;
});
playbackManager.play({
2016-12-15 22:39:51 -05:00
items: currentThemeItems,
2016-12-02 15:10:35 -05:00
fullscreen: false,
enableRemotePlayers: false
}).then(function () {
currentOwnerId = ownerId;
});
2016-08-20 17:58:28 -04:00
} else {
if (currentOwnerId) {
playbackManager.stop();
}
currentOwnerId = null;
}
}
function enabled(mediaType) {
2016-10-18 01:06:48 -04:00
if (mediaType === 'Video') {
2016-09-09 15:03:03 -04:00
return userSettings.enableThemeVideos();
2016-08-20 17:58:28 -04:00
}
2016-09-09 15:03:03 -04:00
return userSettings.enableThemeSongs();
2016-08-20 17:58:28 -04:00
}
function loadThemeMedia(item) {
require(['connectionManager'], function (connectionManager) {
2017-01-11 01:20:44 -05:00
var apiClient = connectionManager.getApiClient(item.ServerId);
2016-08-20 17:58:28 -04:00
apiClient.getThemeMedia(apiClient.getCurrentUserId(), item.Id, true).then(function (themeMediaResult) {
var ownerId = themeMediaResult.ThemeVideosResult.Items.length ? themeMediaResult.ThemeVideosResult.OwnerId : themeMediaResult.ThemeSongsResult.OwnerId;
2016-10-18 01:06:48 -04:00
if (ownerId !== currentOwnerId) {
2016-08-20 17:58:28 -04:00
var items = themeMediaResult.ThemeVideosResult.Items.length ? themeMediaResult.ThemeVideosResult.Items : themeMediaResult.ThemeSongsResult.Items;
playThemeMedia(items, ownerId);
}
});
});
}
document.addEventListener('viewshow', function (e) {
var state = e.detail.state || {};
var item = state.item;
2017-01-11 01:20:44 -05:00
if (item && item.ServerId) {
2016-08-20 17:58:28 -04:00
loadThemeMedia(item);
return;
}
var viewOptions = e.detail.options || {};
if (viewOptions.supportsThemeMedia) {
// Do nothing here, allow it to keep playing
}
else {
playThemeMedia([], null);
}
}, true);
2016-10-15 01:32:06 -04:00
//Events.on(playbackManager, 'playbackstart', function (e, player) {
// var item = playbackManager.currentItem(player);
2016-08-20 17:58:28 -04:00
// // User played something manually
// if (currentThemeIds.indexOf(item.Id) == -1) {
// currentOwnerId = null;
// }
//});
});