Skip to content

Commit

Permalink
Merge pull request #676 from dragonish/lyrics
Browse files Browse the repository at this point in the history
Fix synchronized lyrics that may become unaligned during playback after re-rendering
  • Loading branch information
kgarner7 authored Jul 23, 2024
2 parents 3edc6ba + e106fb3 commit 0b786b0
Showing 1 changed file with 10 additions and 6 deletions.
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

0 comments on commit 0b786b0

Please sign in to comment.