开发
API

BackgroundAudioManager.offTimeUpdate

取消监听 timeUpdate 事件。

语法

BackgroundAudioManager.offTimeUpdate(callback)

参数说明

Function callback

扫码体验

请使用字节宿主APP扫码

代码示例

开发者工具中预览

<!-- index.ttml -->
<button type="primary" bindtap="play">开始播放</button>
<button type="primary" bindtap="pause">暂停播放</button>
<button type="primary" bindtap="offTimeUpdate">取消监听 timeUpdate</button>
// index.js
Page({
  onLoad() {
    const backgroundAudioManager = tt.getBackgroundAudioManager();
    const backgroundAudioManager2 = tt.getBackgroundAudioManager();

    backgroundAudioManager.title = "背景音乐";
    backgroundAudioManager.epname = "测试音频";
    backgroundAudioManager.singer = "测试";
    backgroundAudioManager.coverImgUrl =
      "https://s3.pstatp.com/toutiao/static/img/logo.201f80d.png";
    backgroundAudioManager.onTimeUpdate(() => console.log("onTimeUpdate"));
    this.backgroundAudioManager = backgroundAudioManager;
  },
  play() {
    this.backgroundAudioManager.src =
      "https://sf1-cdn-tos.douyinstatic.com/obj/microapp/frontend/sdk/0000-0001.mp3";
    this.backgroundAudioManager.play();
    console.log(this.backgroundAudioManager.coverImgUrl);
  },
  pause() {
    this.backgroundAudioManager.pause();
  },

  offTimeUpdate() {
    console.log("off");
    this.backgroundAudioManager.offTimeUpdate(() =>
      tt.showToast({ title: "停止监听 timeUpdate 事件" })
    );
  },
});

Bug & Tip

暂无

点击纠错
评价此篇文档