开发
API

BackgroundAudioManager.onTimeUpdate

监听音频进度更新事件,回调执行时机为音频开始播放时,状态更新间隔约为 250ms,暂停或停止播放时音频进度也停止更新。

语法

BackgroundAudioManager.onTimeUpdate(callback)

参数说明

Function callback

扫码体验

请使用字节宿主APP扫码

代码示例

开发者工具中预览

预期表现:点击开始播放时,执行 onTimeUpdate 回调(即调试区打印 onTimeUpdate) ,点击暂停播放暂停执行,开始播放后继续执行。

<!-- index.ttml -->
<button type="primary" bindtap="play">开始播放</button>
<button type="primary" bindtap="pause">暂停播放</button>
// index.js
Page({
  onLoad() {
    const backgroundAudioManager = (this.backgroundAudioManager = tt.getBackgroundAudioManager());
    backgroundAudioManager.title = "背景音乐";
    backgroundAudioManager.epname = "测试音频";
    backgroundAudioManager.singer = "测试";
    backgroundAudioManager.coverImgUrl =
      "https://s3.pstatp.com/toutiao/static/img/logo.201f80d.png";

    backgroundAudioManager.onCanplay(() => console.log("oncanplay"));
    backgroundAudioManager.onPlay(() => console.log("onplay"));
    backgroundAudioManager.onTimeUpdate(() => console.log("onTimeUpdate"));
  },
  play() {
    this.backgroundAudioManager.src = "https://tosv.byted.org/obj/developer/sdk/0000-0001.mp3";
    this.backgroundAudioManager.play();
  },
  pause() {
    this.backgroundAudioManager.pause();
  },
});

Bug & Tip

暂无

点击纠错
评价此篇文档