jellyfin-web/dashboard-ui/scripts/thememediaplayer.js

82 lines
1.8 KiB
JavaScript
Raw Normal View History

2014-04-14 21:23:08 -07:00
(function (document, $, localStorage) {
2014-04-14 20:54:52 -07:00
var currentOwnerId;
var currentThemeIds = [];
function playThemeSongs(items, ownerId) {
var player = getPlayer();
if (items.length && player.isDefaultPlayer && player.canAutoPlayAudio()) {
// Stop if a theme song from another ownerId
// Leave it alone if anything else (e.g user playing a movie)
if (!currentOwnerId && player.isPlaying()) {
return;
}
currentThemeIds = items.map(function (i) {
return i.Id;
});
currentOwnerId = ownerId;
player.play({
items: items
});
} else {
currentOwnerId = null;
}
}
function onPlayItem(item) {
// User played something manually
if (currentThemeIds.indexOf(item.Id) == -1) {
currentOwnerId = null;
}
}
function enabled(isEnabled) {
var userId = Dashboard.getCurrentUserId();
var key = userId + '-themesongs';
2014-04-14 21:23:08 -07:00
if (isEnabled == null) {
return localStorage.getItem(key) == '1';
}
2014-04-14 20:54:52 -07:00
2014-04-14 21:23:08 -07:00
var val = isEnabled ? '1' : '0';
2014-04-14 20:54:52 -07:00
2014-04-14 21:23:08 -07:00
localStorage.setItem(key, val);
2014-04-14 20:54:52 -07:00
}
function getPlayer() {
return MediaController.getCurrentPlayer();
}
$(document).on('thememediadownload', ".libraryPage", function (e, themeMediaResult) {
if (!enabled()) {
return;
}
var ownerId = themeMediaResult.ThemeSongsResult.OwnerId;
if (ownerId != currentOwnerId) {
playThemeSongs(themeMediaResult.ThemeSongsResult.Items, ownerId);
}
});
window.ThemeSongManager = {
2014-04-14 21:23:08 -07:00
enabled: function (isEnabled) {
return enabled(isEnabled);
}
2014-04-14 20:54:52 -07:00
};
2014-04-14 21:23:08 -07:00
})(document, jQuery, window.localStorage);