mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
support theme songs in the web client
This commit is contained in:
parent
b8c3e8c777
commit
b7235c797f
22 changed files with 603 additions and 272 deletions
81
dashboard-ui/scripts/thememediaplayer.js
Normal file
81
dashboard-ui/scripts/thememediaplayer.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
(function (document, $) {
|
||||
|
||||
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';
|
||||
|
||||
if (isEnabled != null) {
|
||||
|
||||
var val = isEnabled ? '1' : '0';
|
||||
|
||||
localStorage.setItem(key, val);
|
||||
|
||||
return;
|
||||
}
|
||||
return localStorage.getItem(key);
|
||||
}
|
||||
|
||||
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 = {
|
||||
enabled: enabled
|
||||
};
|
||||
|
||||
})(document, jQuery);
|
Loading…
Add table
Add a link
Reference in a new issue