开发
API

BackgroundAudioManager.onEnded

监听音频停止事件。触发时机:调用 seek 跳转到音频结尾,或自动播放结束。

语法

BackgroundAudioManager.onEnded(callback)

参数说明

Function callback

扫码体验

请使用字节宿主APP扫码

代码示例

开发者工具中预览

<!-- index.ttml -->
<button type="primary" bindtap="play">开始播放</button>
<button type="primary" bindtap="seek">跳转到音频结尾</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.src = "https://tosv.byted.org/obj/developer/sdk/0000-0001.mp3";
    backgroundAudioManager.onEnded((res) => {
      tt.showToast({ title: "播放结束" });
    });
    this.backgroundAudioManager = backgroundAudioManager;
  },
  play() {
    this.backgroundAudioManager.play();
  },
  seek() {
    this.backgroundAudioManager.seek(1000);
  },
});

Bug & Tip

暂无

点击纠错
评价此篇文档