@xiaohuohumax/lrc-util
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@xiaohuohumax/lrc-util

LRC歌词文件解析辅助工具, 获取当前歌词, 下一句等等

Install

npm i @xiaohuohumax/lrc-util

Use

import lrcSource from './***.lrc?raw';
import { LrcUtil, Lyric } from '@xiaohuohumax/lrc-util';

const lrcUtil = new LrcUtil(lrcSource);

const audio = ref<HTMLAudioElement>(null!);

const nowLyric = ref<Lyric>();
const nextLyric = ref<Lyric>();

function timeUpdate() {
  const time = audio.value.currentTime * 1000;
  // 设置时间
  lrcUtil.setTime(time);
  // 当前歌词
  nowLyric.value = lrcUtil.getLyric();
  // 下一句歌词
  nextLyric.value = lrcUtil.getNextLyric();
}

onMounted(() => {
  timeUpdate();
  audio.value.addEventListener('timeupdate', timeUpdate);
});

example

example-vue

Readme

Keywords

Package Sidebar

Install

npm i @xiaohuohumax/lrc-util

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

11.9 kB

Total Files

7

Last publish

Collaborators

  • xiaohuohumax