syncro lyrics on click
This commit is contained in:
@@ -189,6 +189,31 @@ const MusicDetails = ({ route }) => {
|
||||
console.log("MusicDetails seekBy error", e?.message);
|
||||
}
|
||||
};
|
||||
|
||||
const handleLyricsSeek = React.useCallback(
|
||||
async (timestampS) => {
|
||||
if (!player || typeof timestampS !== "number" || Number.isNaN(timestampS))
|
||||
return;
|
||||
const seconds = Math.max(0, Number(timestampS) || 0);
|
||||
const duration = Number(player?.duration || 0);
|
||||
const bounded = duration > 0 ? Math.min(seconds, duration) : seconds;
|
||||
|
||||
try {
|
||||
const wasPlaying = !!player?.playing;
|
||||
await player.seekTo?.(bounded);
|
||||
setProgressInfo((prev) => ({ ...prev, pos: bounded * 1000 }));
|
||||
if (wasPlaying) {
|
||||
if (!player?.playing) {
|
||||
await player.play?.();
|
||||
}
|
||||
setIsPlaying(true);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("MusicDetails lyrics seek error", e?.message);
|
||||
}
|
||||
},
|
||||
[player]
|
||||
);
|
||||
const description = useMemo(() => {
|
||||
// Build a readable text from lyrics with section labels
|
||||
if (Array.isArray(project?.lyrics)) {
|
||||
@@ -496,6 +521,7 @@ const MusicDetails = ({ route }) => {
|
||||
? styles.karaokeWordActive
|
||||
: styles.karaokeWord
|
||||
}
|
||||
onPress={() => handleLyricsSeek(w.startS)}
|
||||
>
|
||||
{w.text}
|
||||
{j < (L.words?.length || 1) - 1 ? " " : ""}
|
||||
|
||||
Reference in New Issue
Block a user