title: Taro.getBackgroundAudioManager()

sidebar_label: getBackgroundAudioManager

获取全局唯一的背景音频管理器。 小程序切入后台,如果音频处于播放状态,可以继续播放。但是后台状态不能通过调用API操纵音频的播放状态。

从微信客户端6.7.2版本开始,若需要在小程序切后台后继续播放音频,需要在 app.json 中配置 requiredBackgroundModes 属性。开发版和体验版上可以直接生效,正式版还需通过审核。

参考文档

类型

  1. () => BackgroundAudioManager

参数

示例代码

  1. const backgroundAudioManager = Taro.getBackgroundAudioManager()
  2. backgroundAudioManager.title = '此时此刻'
  3. backgroundAudioManager.epname = '此时此刻'
  4. backgroundAudioManager.singer = '许巍'
  5. backgroundAudioManager.coverImgUrl = 'https://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000'
  6. backgroundAudioManager.src = 'https://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46' // 设置了 src 之后会自动播放

API 支持度

API 微信小程序 H5 React Native
Taro.getBackgroundAudioManager ✔️