InnerAudioContext.destroy
销毁当前实例。销毁后该实例将不存在,如需播放需要再次创建。
语法
InnerAudioContext.destroy()
参数说明
无
扫码体验
请使用字节宿主APP扫码
代码示例
<!-- index.ttml -->
<button type="primary" bindtap="create">创建音频实例</button>
<button type="primary" bindtap="play">播放音频</button>
<button type="primary" bindtap="destroy">销毁音频实例</button>
<!-- 销毁后再次点击播放,此时实例已销毁,无反应,需要重新创建音频实例 -->
// index.js
let dataUrl = "https://sf1-ttcdn-tos.pstatp.com/obj/developer/sdk/0000-0001.mp3";
Page({
onShow: function () {
this.create();
},
onUnload() {
this.innerAudioContext && this.innerAudioContext.destroy();
},
play() {
this.innerAudioContext.play();
},
destroy() {
this.innerAudioContext.destroy();
},
create() {
let iac = (this.innerAudioContext = tt.createInnerAudioContext());
iac.src = dataUrl;
iac.autoplay = false;
iac.loop = false;
iac.obeyMuteSwitch = false;
iac.onPlay(() => {
tt.showToast({ title: "开始播放" });
});
iac.onError((err) => {
tt.showModal({
title: "播放出错",
content: err.errMsg,
showCancel: false,
});
});
},
});
Bug & Tip
暂无
点击纠错
评价此篇文档