React Component for Making and Display Lyrics of A Song
- Basic Mode
- Karaoke Mode
- Lyrics Editor
- Apple Music Style (Almost)
npm install github:allape/React-Lyrics
See SimplePlayer for complete demo.
import { Lyrics, TimePoint, useRAFAudioTime } from '@allape/lyrics';
import { ReactElement, useCallback } from 'react';
export function Display({ text, karaoke }: Props): ReactElement {
const [audio, setAudio] = useState<HTMLAudioElement | null>(null);
const [current] = useRAFAudioTime(audio);
const handleChange = useCallback((tp: TimePoint) => {
if (!audio) {
return;
}
audio.currentTime = tp / 1000;
}, [audio]);
return <>
<auido ref={setAudio} src={url} controls/>
<Lyrics
current={current}
content={text}
karaoke={karaoke}
onChange={handleChange}
/>
</>;
}
npm install
npm run dev
See 唐朝乐队 - 国际歌 / Tang Dynasty - L'Internationale for example.