开发
API

BackgroundAudioManager.onWaiting

监听加载中事件,当音频因为数据不足,需要停下来加载时会触发,音频开始播放后需要停下来加载资源时也会触发,此时首先会暂停播放,待资源加载完成后继续播放。

语法

BackgroundAudioManager.onWaiting(callback)

参数说明

Function callback

扫码体验

请使用字节宿主APP扫码

代码示例

开发者工具中预览

<!-- index.ttml -->
<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.onWaiting((res) => {
      tt.showModal({
        title: "音频加载中",
        showCancel: false,
      });
    });
    this.backgroundAudioManager = backgroundAudioManager;
  },
  play() {
    this.backgroundAudioManager.src = "https://tosv.byted.org/obj/developer/sdk/0000-0002.mp3";
    this.backgroundAudioManager.play();
  },
  pause() {
    this.backgroundAudioManager.pause();
  },
});

Bug & Tip

  • Tip:安卓暂不支持此能力。
点击纠错
评价此篇文档