InnerAudioContext.offEnded
取消监听自然播放结束事件。
语法
InnerAudioContext.offEnded(callback)
参数说明
Function callback
扫码体验
请使用字节宿主APP扫码
代码示例
<!-- index.ttml -->
<button type="primary" bindtap="play">播放</button>
<button type="primary" bindtap="seek">跳转到音频结尾</button>
<button type="primary" bindtap="offEnded">取消监听播放结束事件</button>
<!-- 点击“取消监听播放结束事件” 按钮,跳转到音频结尾后没有监听(无弹窗提示) -->
// index.js
let dataUrl =
"https://sf1-ttcdn-tos.pstatp.com/obj/developer/sdk/0000-0001.mp3";
Page({
onShow: function () {
let iac = tt.createInnerAudioContext();
iac.src = dataUrl;
iac.autoplay = false;
iac.loop = false;
iac.obeyMuteSwitch = false;
iac.onCanplay(() => {
console.log(
"onCanplay",
"音频进入可以播放状态,但不保证后面可以流畅播放"
);
});
iac.onPlay(() => {
tt.showToast({ title: "开始播放" });
});
iac.onEnded(() => {
tt.showToast({ title: "播放结束" });
});
iac.onError((err) => {
tt.showModal({
title: "播放出错",
content: err.errMsg,
showCancel: false,
});
});
this.innerAudioContext = iac;
},
onUnload() {
this.innerAudioContext && this.innerAudioContext.destroy();
},
play() {
this.innerAudioContext.play();
},
seek() {
this.innerAudioContext.seek(100);
},
offEnded() {
this.innerAudioContext.offEnded(function() {
tt.showToast({
title: "取消监听播放结束",
});
});
Bug & Tip
暂无
点击纠错
评价此篇文档