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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ew-audio-player

v0.0.1

Published

原生 HTML5 音乐播放器(TypeScript 实现,零依赖,支持播放列表/歌词跟随滚动/播放模式/进度/音量)

Readme

ew-audio-player

原生 HTML5 音乐播放器,TypeScript 实现,零运行时依赖。

功能:播放/暂停、上一曲/下一曲、进度条跳转、音量控制(悬停展开滑条、点击静音)、LRC 歌词跟随滚动(点击歌词跳转)、播放列表、播放模式(列表循环/单曲循环/随机播放)、移动端响应式适配。

安装

npm install ew-audio-player

使用

CSS 与 JS 分离,必须同时引入 CSS(JS 不会自动注入样式):

import "ew-audio-player/dist/style.css";
import { createAudioPlayer } from "ew-audio-player";

const player = createAudioPlayer("#app", {
  tracks: [
    {
      name: "歌曲名",
      src: "/music/demo.mp3",
      // 可选:该曲目的 LRC 歌词文本
      lrc: "[00:01.00]第一句歌词\n[00:05.00]第二句歌词",
    },
  ],
  volume: 0.7,
  autoplay: false,
  mode: "cycle",
});

UMD 全局方式:

<link rel="stylesheet" href="dist/style.css" />
<script src="dist/index.umd.js"></script>
<script>
  const player = window.EwAudioPlayer.createAudioPlayer("#app", { tracks: [...] });
</script>

API

createAudioPlayer(target, options)

  • target:容器元素或选择器字符串。
  • 返回 AudioPlayerInstance,失败(容器不存在 / 无有效曲目)返回 null。

AudioPlayerOptions

| 字段 | 类型 | 默认 | 说明 | | --- | --- | --- | --- | | tracks | AudioTrack[] | 必填 | 播放列表,至少 1 首有效曲目 | | lrc | string | '' | 全局 LRC 歌词文本(track.lrc 优先) | | volume | number | 0.7 | 初始音量 0~1 | | autoplay | boolean | false | 自动播放(被浏览器拦截时静默失败) | | mode | PlayMode | 'cycle' | 初始播放模式 | | className | string | 'ew-audio-player' | 外层容器类名 |

AudioTrack

| 字段 | 类型 | 说明 | | --- | --- | --- | | name | string | 曲目名 | | src | string | 音频地址 | | lrc | string? | 该曲目 LRC 歌词文本 |

PlayMode

'cycle' 列表循环 / 'once' 单曲循环 / 'random' 随机播放。

AudioPlayerInstance

| 成员 | 说明 | | --- | --- | | el | 外层 DOM 容器 | | audio | 原生 <audio> 元素 | | play() / pause() / toggle() | 播放控制 | | next() / prev() | 切歌(random 模式下随机) | | select(index) | 切到指定曲目并播放 | | setMode(mode) | 设置播放模式 | | destroy() | 销毁播放器 |

工具函数

formatTime(sec)、parseLrc(lrc)、bindSlider(...)、ewAudioPlayerGetEle(...) 同样对外导出,可独立复用。

本地示例

pnpm install
pnpm build
pnpm example   # http://localhost:8766/examples/umd.html