Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix synchronized lyrics that may become unaligned during playback after re-rendering #676

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/renderer/features/lyrics/synchronized-lyrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useCurrentTime,
useLyricsSettings,
usePlaybackType,
usePlayerData,
useSeeked,
} from '/@/renderer/store';
import { PlaybackType, PlayerStatus } from '/@/renderer/types';
Expand Down Expand Up @@ -61,6 +62,7 @@ export const SynchronizedLyrics = ({
const playersRef = PlayersRef;
const status = useCurrentStatus();
const playbackType = usePlaybackType();
const playerData = usePlayerData();
const now = useCurrentTime();
const settings = useLyricsSettings();
const centerControls = useCenterControls({ playersRef });
Expand Down Expand Up @@ -109,16 +111,18 @@ export const SynchronizedLyrics = ({
return 0;
}

const player = (
playersRef.current.player1 ?? playersRef.current.player2
).getInternalPlayer();
const player =
playerData.current.player === 1
? playersRef.current.player1
: playersRef.current.player2;
const underlying = player?.getInternalPlayer();

// If it is null, this probably means we added a new song while the lyrics tab is open
// and the queue was previously empty
if (!player) return 0;
if (!underlying) return 0;

return player.currentTime;
}, [playbackType, playersRef]);
return underlying.currentTime;
}, [playbackType, playersRef, playerData]);

const setCurrentLyric = useCallback(
(timeInMs: number, epoch?: number, targetIndex?: number) => {
Expand Down