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

Fixed logic and reduced overhead

This commit is contained in:
ferferga 2020-01-26 14:40:32 +01:00
parent 8f8ebc485d
commit 6bea97ef0f

View file

@ -97,6 +97,15 @@ define(['playbackManager', 'nowPlayingHelper', 'events', 'connectionManager'], f
} }
function updatePlayerState(player, state, eventName) { function updatePlayerState(player, state, eventName) {
var now = new Date().getTime();
lastUpdateTime = now;
// Don't go crazy reporting position changes
if (eventName == 'timeupdate' && (now - lastUpdateTime) < 5000) {
// Only report if this item hasn't been reported yet, or if there's an actual playback change.
// Don't report on simple time updates
return;
}
var item = state.NowPlayingItem; var item = state.NowPlayingItem;
@ -118,19 +127,9 @@ define(['playbackManager', 'nowPlayingHelper', 'events', 'connectionManager'], f
} }
var playState = state.PlayState || {}; var playState = state.PlayState || {};
var parts = nowPlayingHelper.getNowPlayingNames(item); var parts = nowPlayingHelper.getNowPlayingNames(item);
var artist = parts[parts.length - 1].text;
var artist = parts.length === 1 ? '' : parts[0].text; var title = parts.length === 1 ? '' : parts[0].text;
var title = parts[parts.length - 1].text;
// Switch these two around for video
if (isVideo && parts.length > 1) {
var temp = artist;
artist = title;
title = temp;
}
var albumArtist; var albumArtist;
if (item.AlbumArtists && item.AlbumArtists[0]) { if (item.AlbumArtists && item.AlbumArtists[0]) {
@ -147,21 +146,10 @@ define(['playbackManager', 'nowPlayingHelper', 'events', 'connectionManager'], f
var isPaused = playState.IsPaused || false; var isPaused = playState.IsPaused || false;
var canSeek = playState.CanSeek || false; var canSeek = playState.CanSeek || false;
var now = new Date().getTime();
// Don't go crazy reporting position changes
if (eventName == 'timeupdate' && (now - lastUpdateTime) < 5000) {
// Only report if this item hasn't been reported yet, or if there's an actual playback change.
// Don't report on simple time updates
return;
}
lastUpdateTime = now;
if (navigator.mediaSession) { if (navigator.mediaSession) {
navigator.mediaSession.metadata = new MediaMetadata({ navigator.mediaSession.metadata = new MediaMetadata({
title: artist, title: title,
artist: title, artist: artist,
album: album, album: album,
artwork: getImageUrls(item), artwork: getImageUrls(item),
albumArtist: albumArtist, albumArtist: albumArtist,
@ -185,8 +173,8 @@ define(['playbackManager', 'nowPlayingHelper', 'events', 'connectionManager'], f
action: eventName, action: eventName,
isLocalPlayer: isLocalPlayer, isLocalPlayer: isLocalPlayer,
itemId: itemId, itemId: itemId,
title: artist, title: title,
artist: title, artist: artist,
album: album, album: album,
duration: duration, duration: duration,
position: currentTime, position: currentTime,