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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@haoqimao/wx-background-audio

v0.0.4

Published

微信小程序背景音乐播放

Readme

wx-background-audio

介绍

微信小程序背景音乐播放

引用示例

  // 直接引用默认实例
  const BackgroundAudio = require('@haoqimao/wx-background-audio')
  // 自定义实例
  const BackgroundAudio = require('@haoqimao/wx-background-audio')
  const BackgroundAudio1 = BackgroundAudio.create({
    key = '', // 当前背景播放唯一标识
    title = '音频', // 音频标题,必填
    startTime = 0, // 音频开始播放的位置(单位:s)
    epname = '', // 专辑名称,分享使用
    singer = '佚名', // 歌手名,分享使用
    coverImgUrl = '', // 封面图 URL,用于做原生音频播放器背景图
    webUrl = '', // 页面链接,原生音频播放器中的分享功能,分享出去的卡片简介,也将使用该值
    protocol = 'http', // 音频协议。默认值为 'http',设置 'hls' 可以支持播放 HLS 协议的直播音频
  })

使用示例

const BackgroundAudio from '@haoqimao/wx-background-audio'

// 绑定的事件
const playOn = ()=> {
  return {
    onBeforePlay = null, // 播放回调,非官方回调
    key: rebindKey = null, // 重新绑定key
    onCanplay = null,
    onEnded = null,
    onError = null,
    onNext = null,
    onPause = null,
    onPlay = null,
    onPrev = null,
    onSeeked = null,
    onSeeking = null,
    onStop = null,
    onTimeUpdate = null,
    onWaiting = null,
  }
}

// 播放音乐
BackgroundAudio.play({
  src: this.data.mp3,
  key: this.data.mp3,
  duration: this.data.duration, // 音频的长度(单位:s)
  progress: this.data.progress, // 当前播放进度[0-100]
  ...playOn()
})

// 暂停音乐
BackgroundAudio.pause()

// 绑定事件
BackgroundAudio.on({
  key: this.data.mp3,
  ...this.playOn(),
}).then()

暴露属性|方法

|名称|描述| |---|---| |duration| 当前音频的长度(单位:s) | |progress|当前音频的进度 [ 0 - 100 ] | |currentTime|当前音频的播放位置(单位:s),只有在有合法 src 时返回 | |src|获取当前播放音频的地址 | |paused|当前是否暂停或停止 | |buffered|音频已缓冲的时间仅保证当前播放时间点到此时间点内容已缓冲 | |play| 播放音乐 title = '音频', // 音频标题,必填src = '', // 当设置了新的 src 时,会自动开始播放,目前支持的格式有 m4a, aac, mp3, wav。startTime = -1, // 音频开始播放的位置(单位:s)progress = -1, // 音频开始播放的位置(单位:百分比)epname = '', // 专辑名称,分享使用singer = '佚名', // 歌手名,分享使用coverImgUrl = '', // 封面图 URL,用于做原生音频播放器背景图webUrl = '', // 页面链接,原生音频播放器中的分享功能,分享出去的卡片简介,也将使用该值protocol = 'http', // 音频协议。默认值为 'http',设置 'hls' 可以支持播放 HLS 协议的直播音频key = '', //duration = 0, // 持续时间| |seek|跳转到指定位置num: 跳转的位置,单位 s。精确到小数点后 3 位,即支持 ms 级别精确度type: 0:使用百分比跳转;1:使用秒数跳转 | |stop| 停止音乐 | |pause| 暂停播放 | |on| 绑定事件,详情参考 微信官网 |