2016-09-09 12:03:03 -07:00
|
|
|
define(['playbackManager', 'userSettings'], function (playbackManager, userSettings) {
|
2016-10-17 22:06:48 -07:00
|
|
|
'use strict';
|
2016-08-20 14:58:28 -07:00
|
|
|
|
|
|
|
var currentOwnerId;
|
|
|
|
var currentThemeIds = [];
|
|
|
|
|
|
|
|
function playThemeMedia(items, ownerId) {
|
|
|
|
|
2016-12-15 20:39:51 -07:00
|
|
|
var currentThemeItems = items.filter(function (i) {
|
|
|
|
return enabled(i.MediaType);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (currentThemeItems.length) {
|
2016-08-20 14:58:28 -07: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 20:39:51 -07:00
|
|
|
currentThemeIds = currentThemeItems.map(function (i) {
|
2016-12-02 13:10:35 -07:00
|
|
|
return i.Id;
|
|
|
|
});
|
|
|
|
|
|
|
|
playbackManager.play({
|
2016-12-15 20:39:51 -07:00
|
|
|
items: currentThemeItems,
|
2016-12-02 13:10:35 -07:00
|
|
|
fullscreen: false,
|
|
|
|
enableRemotePlayers: false
|
|
|
|
}).then(function () {
|
|
|
|
currentOwnerId = ownerId;
|
|
|
|
});
|
2016-08-20 14:58:28 -07:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (currentOwnerId) {
|
|
|
|
playbackManager.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
currentOwnerId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function enabled(mediaType) {
|
|
|
|
|
2016-10-17 22:06:48 -07:00
|
|
|
if (mediaType === 'Video') {
|
2016-09-09 12:03:03 -07:00
|
|
|
return userSettings.enableThemeVideos();
|
2016-08-20 14:58:28 -07:00
|
|
|
}
|
|
|
|
|
2016-09-09 12:03:03 -07:00
|
|
|
return userSettings.enableThemeSongs();
|
2016-08-20 14:58:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadThemeMedia(item) {
|
|
|
|
|
|
|
|
require(['connectionManager'], function (connectionManager) {
|
|
|
|
|
2017-01-10 23:20:44 -07:00
|
|
|
var apiClient = connectionManager.getApiClient(item.ServerId);
|
2016-08-20 14:58:28 -07: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-17 22:06:48 -07:00
|
|
|
if (ownerId !== currentOwnerId) {
|
2016-08-20 14:58:28 -07: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-10 23:20:44 -07:00
|
|
|
if (item && item.ServerId) {
|
2016-08-20 14:58:28 -07: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-14 22:32:06 -07:00
|
|
|
//Events.on(playbackManager, 'playbackstart', function (e, player) {
|
|
|
|
// var item = playbackManager.currentItem(player);
|
2016-08-20 14:58:28 -07:00
|
|
|
// // User played something manually
|
|
|
|
// if (currentThemeIds.indexOf(item.Id) == -1) {
|
|
|
|
// currentOwnerId = null;
|
|
|
|
// }
|
|
|
|
//});
|
|
|
|
|
|
|
|
});
|