1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/scripts/thememediaplayer.js

76 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-03-07 14:13:58 -05:00
define(['appStorage'], function (appStorage) {
2014-04-14 23:54:52 -04: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 14:38:12 -04:00
function enabled() {
2014-04-14 23:54:52 -04:00
2014-05-21 23:35:18 -04:00
var userId = Dashboard.getCurrentUserId();
2014-07-21 21:29:06 -04:00
2015-05-20 13:29:26 -04:00
var val = appStorage.getItem('enableThemeSongs-' + userId);
2014-04-14 23:54:52 -04:00
2015-05-08 23:48:43 -04:00
var localAutoPlayers = MediaController.getPlayers().filter(function (p) {
return p.isLocalPlayer && p.canAutoPlayAudio();
});
2014-07-11 22:31:08 -04:00
// For bandwidth
2015-05-08 23:48:43 -04:00
return val == '1' || (val != '0' && localAutoPlayers.length);
2014-04-14 23:54:52 -04:00
}
function getPlayer() {
return MediaController.getCurrentPlayer();
}
2015-12-14 10:43:03 -05:00
document.addEventListener('thememediadownload', function (e) {
2014-04-14 23:54:52 -04:00
if (!enabled()) {
return;
}
2015-12-14 10:43:03 -05:00
var themeMediaResult = e.detail.themeMediaResult;
2014-04-14 23:54:52 -04:00
var ownerId = themeMediaResult.ThemeSongsResult.OwnerId;
if (ownerId != currentOwnerId) {
playThemeSongs(themeMediaResult.ThemeSongsResult.Items, ownerId);
}
});
2016-03-07 14:13:58 -05:00
});