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

76 lines
1.8 KiB
JavaScript
Raw Normal View History

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