作者:亲亲萌萌baby0106_671 | 来源:互联网 | 2023-05-17 10:42
很简单的一个音乐播放器data:{src:http:ws.stream.qqmusic.qq.comM500001VfvsJ21xFqb.mp3?guidfffffff
很简单的一个音乐播放器
data:{
src: 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&fromtag=46',
currentTime: 0,
duration: 0,
result: '00:00',
}
onLoad: function (e) {
// 使用 wx.createAudioContext 获取 audio 上下文 context
this.audioCtx = wx.createAudioContext('myAudio')
var that=this;
wx.setNavigationBarTitle({
title: that.data.name
});
},
audioPlay: function () {
this.audioCtx.play()
this.setData({
isOpen: true
})
},
audioPause: function () {
this.audioCtx.pause()
this.setData({
isOpen: false
})
},
updata(e) {
var that = this;
// console.log((e.detail.currentTime / 100).toFixed(2))
let duration = e.detail.duration.toFixed(2) * 100,
currentTime = e.detail.currentTime.toFixed(2) * 100;
that.setData({
duration: duration,
currentTime: currentTime
})
that.formatSeconds(currentTime / 100);
},
sliderChange(e) {
var that = this
that.setData({
currentTime: e.detail.value
})
that.audioSeek(e.detail.value)
},
audioSeek: function (currentTime) {
this.audioCtx.seek(currentTime / 100)
},
wxml