开发
API

BackgroundAudioManager.onError

监听音频播放错误事件。包括设置的属性类型不合法,API 调用过程中错误等。

语法

BackgroundAudioManager.onError(callback)

参数说明

Function callback

扫码体验

请使用字节宿主APP扫码

代码示例

开发者工具中预览

<button type="primary" bindtap="play">开始播放</button>
<button type="primary" bindtap="pause">暂停播放</button>
// index.js
Page({
  onLoad() {
    const backgroundAudioManager = tt.getBackgroundAudioManager();
    backgroundAudioManager.title = "背景音乐";
    backgroundAudioManager.epname = "测试音频";
    backgroundAudioManager.singer = "测试";
    backgroundAudioManager.coverImgUrl =
      "https://s3.pstatp.com/toutiao/static/img/logo.201f80d.png";
    backgroundAudioManager.onError((err) => {
      if (err.errMsg) {
        tt.showModal({
          title: "播放出错",
          content: err.errMsg,
          showCancel: false,
        });
      }
    });
    this.backgroundAudioManager = backgroundAudioManager;
  },
  play() {
    this.backgroundAudioManager.src = 0; // error src
    this.backgroundAudioManager.play();
  },
  pause() {
    this.backgroundAudioManager.pause();
  },
});

Bug & Tip

暂无

点击纠错
评价此篇文档