From 53311a17284ccb4d811de9b30dc4ab526de54ed4 Mon Sep 17 00:00:00 2001 From: Prayag Prajapati Date: Tue, 1 Jul 2025 22:04:55 +0530 Subject: [PATCH] fix: seekTo not working as intended --- src/routes/_api/player/index.tsx | 7 ++++--- src/utils/store/playback.ts | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/routes/_api/player/index.tsx b/src/routes/_api/player/index.tsx index 29eeb0d..77f3b38 100644 --- a/src/routes/_api/player/index.tsx +++ b/src/routes/_api/player/index.tsx @@ -101,7 +101,7 @@ export function VideoPlayer() { toggleIsPlayerMuted, // nextSegmentIndex, // activeSegmentId, - // clearActiveSegment, + clearActiveSegment, // setActiveSegment, playbackStream, setIsBuffering, @@ -127,7 +127,7 @@ export function VideoPlayer() { toggleIsPlayerFullscreen: state.toggleIsPlayerFullscreen, // nextSegmentIndex: state.nextSegmentIndex, // activeSegmentId: state.activeSegmentId, - // clearActiveSegment: state.clearActiveSegment, + clearActiveSegment: state.clearActiveSegment, // setActiveSegment: state.setActiveSegment, playbackStream: state.playbackStream, setIsBuffering: state.setIsBuffering, @@ -145,7 +145,7 @@ export function VideoPlayer() { const handleReady = async () => { if (api && !isPlayerReady && player.current) { - player.current.fastSeek(ticksToSec(userDataLastPlayedPositionTicks ?? 0)); + player.current.currentTime = ticksToSec(userDataLastPlayedPositionTicks ?? 0); registerPlayerActions({ seekTo: (seconds: number) => { const internalPlayer = player.current; @@ -346,6 +346,7 @@ export function VideoPlayer() { const handlePlaybackEnded = useCallback(() => { if (queue?.length !== currentQueueItemIndex + 1) { + clearActiveSegment(); // Clear active segment when playback ends playItemFromQueue("next", user?.Id, api); } else { handleExitPlayer(); // Exit player if playback has finished and the queue is empty diff --git a/src/utils/store/playback.ts b/src/utils/store/playback.ts index ad19d73..e6833e0 100644 --- a/src/utils/store/playback.ts +++ b/src/utils/store/playback.ts @@ -498,10 +498,12 @@ export const usePlaybackStore = create< return 0; }, }, - registerPlayerActions: (actions) => + registerPlayerActions: (actions) => { + console.info("Registering player actions:", actions); set({ _playerActions: actions, - }), + }); + }, seekTo: (seconds: number) => { const playerActions = get()._playerActions; playerActions.seekTo(seconds); @@ -576,7 +578,7 @@ export const usePlaybackStore = create< // Update current time to the new seek value set((state) => { state.playerState.isUserSeeking = false; - // state.playerState.currentTime = ticks; + state.playerState.currentTime = ticks; }); }, })),