Skip to content

🎧 Your Personal Streaming Service

fix(ui): report playback when restarting current track via prev

Deluan0265ff3ad18b
diff --git a/ui/src/audioplayer/Player.jsx b/ui/src/audioplayer/Player.jsx
index e2070deea..c3d795b26 100644
--- a/ui/src/audioplayer/Player.jsx
+++ b/ui/src/audioplayer/Player.jsx
@@ -272,18 +272,6 @@ const Player = () => {
}
}, [])
- const onAudioSeeked = useCallback(
- (info) => {
- if (!info.isRadio && currentTrackId) {
- const posMs = Math.floor(info.currentTime * 1000)
- lastPositionMsRef.current = posMs
- const state = audioInstance?.paused ? 'paused' : 'playing'
- subsonic.reportPlayback(currentTrackId, posMs, state)
- }
- },
- [currentTrackId, audioInstance],
- )
-
const onAudioVolumeChange = useCallback(
// sqrt to compensate for the logarithmic volume
(volume) => dispatch(setVolume(Math.sqrt(volume))),
@@ -436,6 +424,35 @@ const Player = () => {
}
}, [isMobilePlayer, audioInstance])
+ // Report every seek (including programmatic ones the library does not surface
+ // via onAudioSeeked, e.g. restartCurrentOnPrev). Debounce coalesces drag
+ // bursts into one report at the final position.
+ useEffect(() => {
+ if (!audioInstance) return
+ let timer = null
+ const flush = () => {
+ timer = null
+ if (
+ !currentTrackIdRef.current ||
+ playerStateRef.current?.current?.isRadio
+ ) {
+ return
+ }
+ const posMs = Math.floor((audioInstance.currentTime || 0) * 1000)
+ const state = audioInstance.paused ? 'paused' : 'playing'
+ subsonic.reportPlayback(currentTrackIdRef.current, posMs, state)
+ }
+ const handleSeeked = () => {
+ if (timer) clearTimeout(timer)
+ timer = setTimeout(flush, 250)
+ }
+ audioInstance.addEventListener('seeked', handleSeeked)
+ return () => {
+ if (timer) clearTimeout(timer)
+ audioInstance.removeEventListener('seeked', handleSeeked)
+ }
+ }, [audioInstance])
+
return (
<ThemeProvider theme={createMuiTheme(theme)}>
<ReactJkMusicPlayer
@@ -444,7 +461,6 @@ const Player = () => {
onAudioListsChange={onAudioListsChange}
onAudioVolumeChange={onAudioVolumeChange}
onAudioProgress={onAudioProgress}
- onAudioSeeked={onAudioSeeked}
onAudioPlay={onAudioPlay}
onAudioPlayTrackChange={onAudioPlayTrackChange}
onAudioPause={onAudioPause}