1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/components/themeMediaPlayer.js

102 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-08-14 08:46:34 +02:00
import playbackManager from './playback/playbackmanager';
import * as userSettings from '../scripts/settings/userSettings';
import connectionManager from 'jellyfin-apiclient';
let currentOwnerId;
let currentThemeIds = [];
2020-07-31 09:12:44 +01:00
function playThemeMedia(items, ownerId) {
const currentThemeItems = items.filter(function (i) {
return enabled(i.MediaType);
});
if (currentThemeItems.length) {
// 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;
}
2018-10-23 01:05:09 +03:00
currentThemeIds = currentThemeItems.map(function (i) {
return i.Id;
});
playbackManager.play({
items: currentThemeItems,
fullscreen: false,
enableRemotePlayers: false
}).then(function () {
currentOwnerId = ownerId;
});
} else {
stopIfPlaying();
2018-10-23 01:05:09 +03:00
}
}
2018-10-23 01:05:09 +03:00
function stopIfPlaying() {
if (currentOwnerId) {
playbackManager.stop();
2018-10-23 01:05:09 +03:00
}
currentOwnerId = null;
}
function enabled(mediaType) {
if (mediaType === 'Video') {
return userSettings.enableThemeVideos();
}
return userSettings.enableThemeSongs();
}
const excludeTypes = ['CollectionFolder', 'UserView', 'Program', 'SeriesTimer', 'Person', 'TvChannel', 'Channel'];
function loadThemeMedia(item) {
if (item.CollectionType) {
stopIfPlaying();
return;
}
if (excludeTypes.indexOf(item.Type) !== -1) {
stopIfPlaying();
return;
2018-10-23 01:05:09 +03:00
}
2020-08-30 06:06:47 +02:00
const apiClient = window.connectionManager.getApiClient(item.ServerId);
apiClient.getThemeMedia(apiClient.getCurrentUserId(), item.Id, true).then(function (themeMediaResult) {
const ownerId = themeMediaResult.ThemeVideosResult.Items.length ? themeMediaResult.ThemeVideosResult.OwnerId : themeMediaResult.ThemeSongsResult.OwnerId;
if (ownerId !== currentOwnerId) {
const items = themeMediaResult.ThemeVideosResult.Items.length ? themeMediaResult.ThemeVideosResult.Items : themeMediaResult.ThemeSongsResult.Items;
playThemeMedia(items, ownerId);
}
});
}
document.addEventListener('viewshow', function (e) {
const state = e.detail.state || {};
const item = state.item;
if (item && item.ServerId) {
loadThemeMedia(item);
return;
}
const viewOptions = e.detail.options || {};
if (viewOptions.supportsThemeMedia) {
// Do nothing here, allow it to keep playing
} else {
playThemeMedia([], null);
}
}, true);
Events.on(playbackManager, 'playbackstart', function (e, player) {
const item = playbackManager.currentItem(player);
// User played something manually
if (currentThemeIds.indexOf(item.Id) == -1) {
currentOwnerId = null;
}
});