npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lrc-player/core

v1.1.4

Published

用于音乐播放器的歌词渲染

Downloads

55

Readme

@lrc-player/core 用于音乐播放器的歌词渲染

GitHub: https://github.com/1727533196/lrc-player

生态作品: https://gitee.com/wa-da-sheng-dao_0/vue3-electron-netease-cloud

这个包为原生dom绑定,使用class来进行编写

安装

选择一个你当前项目中使用的包管理工具

npm: npm install @lrc-player/core@latest
yarn: yarn add @lrc-player/core@latest
pnpm: pnpm add @lrc-player/core@latest

在这里提供了一个帮助解析歌词的插件包
npm install @lrc-player/parse@latest
详细使用可以查看https://www.npmjs.com/package/@lrc-player/parse

初始化

import '@lrc-player/core/dist/style.css' // 引入样式
import { parseLrc, parseYrc } from '@lrc-player/parse'
import Player from '@lrc-player/core'

const player = new Player({
  // 当点击任意歌词行时,会触发这个事件
  click(time: number, index: number) {
    console.log(time, index)
    audio.value!.currentTime = time
    player.syncIndex(index)
  }
})

// 挂载元素,确保这一步是最早且只需要挂载一次
//  第二个参数不一定必须是audio,只需要确认这个对象里包含 currentTime:number 属性即可(并且是实时更新的)
player.mount(document.querySelector('#app') as HTMLElement, audio)

// 更新url与歌词,通常在切换下一首或上一首时调用这个
// parseLrc是这个包里提供的解析歌词函数https://www.npmjs.com/package/@lrc-player/parse
const lrc = parseLrc('[11700,1410](11700,510,0)Let (12210,390,0)me (12600,510,0)know')
// 需要确认是逐字歌词还是逐行歌词,在这里是逐字,所以传入类型为lrc
player.updateAudioLrc(lrc, 'lrc')

// 开始播放音乐
audio.play()
// 开始同步歌词
player.play()

// 弱使用的是vue或react,组件被销毁时,需要卸载Player实例
// react:
useEffect(() => {
  return () => {
    player.uninstall()
  }
}, [])

// vue:
onUnmounted(() => {
  player.uninstall()
})

API

function

  • player.play() 开始播放
    • params:无参数
  • player.pause() 暂停
    • params:无参数
  • player.updateAudioLrc(lrc, type: 'lrc' | 'yrc') 更新歌词
  • player.syncIndex() 同步歌词当前行,调用它可更改当前播放行
    • index?: number 若没有传入index,则会根据currentTime来自动同步当前行.(如果明确index,推荐传入以减少额外开销)
  • player.uninstall() 卸载