2020-08-06 11:41:45 +01:00
|
|
|
import playbackManager from 'playbackManager';
|
|
|
|
import userSettings from 'userSettings';
|
|
|
|
import connectionManager from 'connectionManager';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
let currentOwnerId;
|
|
|
|
let currentThemeIds = [];
|
2020-07-31 09:12:44 +01:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
function playThemeMedia(items, ownerId) {
|
|
|
|
const currentThemeItems = items.filter(function (i) {
|
|
|
|
return enabled(i.MediaType);
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
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;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
currentThemeIds = currentThemeItems.map(function (i) {
|
|
|
|
return i.Id;
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
playbackManager.play({
|
|
|
|
items: currentThemeItems,
|
|
|
|
fullscreen: false,
|
|
|
|
enableRemotePlayers: false
|
|
|
|
}).then(function () {
|
|
|
|
currentOwnerId = ownerId;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
stopIfPlaying();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-08-06 11:41:45 +01:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
function stopIfPlaying() {
|
|
|
|
if (currentOwnerId) {
|
|
|
|
playbackManager.stop();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
currentOwnerId = null;
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
function enabled(mediaType) {
|
|
|
|
if (mediaType === 'Video') {
|
|
|
|
return userSettings.enableThemeVideos();
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
return userSettings.enableThemeSongs();
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
const excludeTypes = ['CollectionFolder', 'UserView', 'Program', 'SeriesTimer', 'Person', 'TvChannel', 'Channel'];
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
function loadThemeMedia(item) {
|
|
|
|
if (item.CollectionType) {
|
|
|
|
stopIfPlaying();
|
|
|
|
return;
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
if (excludeTypes.indexOf(item.Type) !== -1) {
|
|
|
|
stopIfPlaying();
|
|
|
|
return;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
const apiClient = 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;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
if (ownerId !== currentOwnerId) {
|
|
|
|
const items = themeMediaResult.ThemeVideosResult.Items.length ? themeMediaResult.ThemeVideosResult.Items : themeMediaResult.ThemeSongsResult.Items;
|
|
|
|
|
|
|
|
playThemeMedia(items, ownerId);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-08-06 11:41:45 +01:00
|
|
|
});
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
document.addEventListener('viewshow', function (e) {
|
|
|
|
const state = e.detail.state || {};
|
|
|
|
const item = state.item;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
if (item && item.ServerId) {
|
|
|
|
loadThemeMedia(item);
|
|
|
|
return;
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:45 +01:00
|
|
|
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;
|
|
|
|
}
|
2020-02-22 11:47:03 -05:00
|
|
|
});
|
2020-08-06 11:41:45 +01:00
|
|
|
|