武田小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.5 KiB

6 months ago
const _app = getApp<IAppOption>();
// pages/story/a.ts
Component({
/**
*
*/
6 months ago
properties: {
url: {
type: String,
6 months ago
value: "",
// 'https://circlehbsaas.oss-cn-beijing.aliyuncs.com/audio/20240907757_tmp_acf4f18c59553a8d2d9f74e173a16328.m4a.mp3',
6 months ago
},
time: {
type: String,
6 months ago
value: "",
6 months ago
},
},
/**
*
*/
6 months ago
data: {
play: false,
innerAudioContext: null as WechatMiniprogram.InnerAudioContext | null,
},
lifetimes: {
attached() {
this.setData({
innerAudioContext: wx.createInnerAudioContext(),
6 months ago
});
6 months ago
},
6 months ago
detached() {
if (this.data.innerAudioContext) {
this.data.innerAudioContext?.stop();
this.data.innerAudioContext.destroy()
}
},
6 months ago
},
/**
*
*/
6 months ago
methods: {
handlePlay() {
6 months ago
const { url, play, innerAudioContext } = this.data;
6 months ago
if (innerAudioContext) {
if (play) {
6 months ago
innerAudioContext.stop();
return;
6 months ago
}
6 months ago
innerAudioContext.stop();
innerAudioContext.src = url;
innerAudioContext.play();
6 months ago
this.setData({
play: true,
6 months ago
});
6 months ago
innerAudioContext.onEnded(() => {
this.setData({
play: false,
6 months ago
});
});
6 months ago
}
},
handlePause() {
6 months ago
const { innerAudioContext } = this.data;
6 months ago
if (innerAudioContext) {
6 months ago
innerAudioContext.pause();
6 months ago
this.setData({
play: false,
6 months ago
});
6 months ago
}
},
},
6 months ago
});
export {};