武田小程序
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.

71 lines
1.3 KiB

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