miniprogram-demo/packageAPI/pages/innerAudioContext/index.js

73 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-08-10 15:29:31 +08:00
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
2022-02-21 15:20:22 +08:00
volume: 1,
rate: 1,
2021-08-10 15:29:31 +08:00
},
2022-02-21 15:20:22 +08:00
onLoad() {
2021-08-10 15:29:31 +08:00
const innerAudioContext = wx.createInnerAudioContext()
this.ctx = innerAudioContext
console.log(innerAudioContext)
2022-02-21 15:20:22 +08:00
2021-08-10 15:29:31 +08:00
// innerAudioContext.playbackRate = 2.0
2022-02-21 15:20:22 +08:00
// innerAudioContext.src = '/packageAPI/pages/innerAudioContext/mucis.mp3'
2021-08-10 15:29:31 +08:00
// innerAudioContext.src = 'http://cdn.amathclass.cn/quesAudio/42fe780d-1607959109843.m4a'
2022-02-21 15:20:22 +08:00
innerAudioContext.src = 'https://public-1251849568.cos.ap-guangzhou.myqcloud.com/temp/mucis.mp3'
2021-08-10 15:29:31 +08:00
const listener = ['Canplay', 'Ended', 'Pause', 'Play', 'Seeked', 'Seeking', 'Stop', 'TimeUpdate', 'Waiting']
2022-02-21 15:20:22 +08:00
listener.forEach(key => {
innerAudioContext['on' + key](() => {
console.log('on' + key)
2021-08-10 15:29:31 +08:00
})
})
innerAudioContext.onError((res) => {
console.log(res.errMsg)
console.log(res)
console.log(res.errCode)
})
// innerAudioContext.onWaiting((res)=>{
// console.log(res)
// console.log('wait')
// })
},
onUnload() {
this.ctx.destroy()
console.log(this.ctx)
},
2022-02-21 15:20:22 +08:00
play() {
this.ctx.play()
// this.ctx.src = '/mucis.mp3'
// this.ctx.autoplay = true
2021-08-10 15:29:31 +08:00
},
2022-02-21 15:20:22 +08:00
seek() {
2021-08-10 15:29:31 +08:00
this.ctx.seek(60)
},
2022-02-21 15:20:22 +08:00
pause() {
2021-08-10 15:29:31 +08:00
this.ctx.pause()
},
2022-02-21 15:20:22 +08:00
destroy() {
2021-08-10 15:29:31 +08:00
this.ctx.destroy()
console.log(this.ctx)
},
2022-02-21 15:20:22 +08:00
stop() {
2021-08-10 15:29:31 +08:00
this.ctx.stop()
},
2022-02-21 15:20:22 +08:00
handleVolumeChange(e) {
2021-08-10 15:29:31 +08:00
this.setData({
2022-02-21 15:20:22 +08:00
volume: e.detail.value
2021-08-10 15:29:31 +08:00
})
this.ctx.volume = this.data.volume
},
2022-02-21 15:20:22 +08:00
handleRateChange(e) {
2021-08-10 15:29:31 +08:00
this.setData({
2022-02-21 15:20:22 +08:00
rate: e.detail.value
2021-08-10 15:29:31 +08:00
})
this.ctx.playbackRate = this.data.rate
}
})