fix: properly end previous playing track

This commit is contained in:
Lei Nelissen
2023-06-18 22:04:20 +02:00
parent f540424edd
commit 8ff785da40
2 changed files with 12 additions and 4 deletions

View File

@@ -36,12 +36,17 @@ export default async function() {
TrackPlayer.seekTo(event.position);
});
TrackPlayer.addEventListener(Event.PlaybackTrackChanged, () => {
TrackPlayer.addEventListener(Event.PlaybackTrackChanged, async (e) => {
// Retrieve the current settings from the Redux store
const settings = store.getState().settings;
// GUARD: Only report playback when the settings is enabled
if (settings.enablePlaybackReporting) {
if (settings.enablePlaybackReporting && 'track' in e) {
// GUARD: End the previous track if it's about to end
if ('nextTrack' in e && typeof e.track === 'number') {
sendPlaybackEvent('/Sessions/Stopped', settings.jellyfin, e.track);
}
sendPlaybackEvent('/Sessions/Playing', settings.jellyfin);
}
});