InnerAudioContext.offStop
取消监听 stop 事件。
语法
InnerAudioContext.offStop(callback)
参数说明
Function callback
扫码体验
请使用字节宿主APP扫码
代码示例
<!-- index.ttml -->
<button type="primary" bindtap="create">创建音频实例</button>
<button type="primary" bindtap="play">播放</button>
<button type="primary" bindtap="stop">停止播放</button>
<button type="primary" bindtap="offListen">取消监听音频停止</button>
<button type="primary" bindtap="destroy">销毁音频实例</button>
<!-- 创建音频实例后直接播放,监听 stop 事件 -->
<!-- 创建音频实例后,点击取消监听,再次点击播放时则不再监听 stop -->
// index.js
let dataUrl = "https://sf1-ttcdn-tos.pstatp.com/obj/developer/sdk/0000-0001.mp3";
Page({
onShow: function () {},
onUnload() {
this.innerAudioContext && this.innerAudioContext.destroy();
},
create() {
let iac = tt.createInnerAudioContext();
iac.autoplay = false;
iac.loop = false;
iac.obeyMuteSwitch = false;
iac.onPlay(() => {
tt.showToast({ title: "音频开始播放" });
});
iac.onStop(() => {
tt.showToast({ title: "音频停止播放" });
});
iac.onError((err) => {
tt.showModal({
title: "播放出错",
content: err.errMsg,
showCancel: false,
});
});
this.innerAudioContext = iac;
},
play() {
if (this.innerAudioContext) {
this.innerAudioContext.src = dataUrl;
this.innerAudioContext.play();
}
},
stop() {
this.innerAudioContext && this.innerAudioContext.stop();
},
offListen() {
if (this.innerAudioContext) {
this.innerAudioContext.offStop();
tt.showToast({ title: "取消监听 stop" });
}
},
destroy() {
this.innerAudioContext && this.innerAudioContext.destroy();
},
});
Bug & Tip
暂无
点击纠错
评价此篇文档