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

70 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-07-15 12:16:16 -07:00
(function (document, $) {
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;
}
}
2014-05-21 11:38:12 -07:00
function enabled() {
2014-04-14 20:54:52 -07:00
2014-05-21 20:35:18 -07:00
var userId = Dashboard.getCurrentUserId();
2014-07-15 12:16:16 -07:00
var val = store.getItem('enableThemeSongs', userId);
2014-04-14 20:54:52 -07:00
2014-07-11 19:31:08 -07:00
// For bandwidth
return val == '1' || (val != '0' && !$.browser.mobile);
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);
}
});
2014-07-15 12:16:16 -07:00
})(document, jQuery);