音乐视屏播放,歌词展示,暂停/播放/上一首/下一首
|
01
02
03
04
05
06
07
08
09
10
11
12
|
playAndPause: function () {
var that = this
if (that.data.isPlaying) {
wx.pauseBackgroundAudio()
} else {
wx.playBackgroundAudio()
}
that.playSong()
that.setData({
isPlaying: !that.data.isPlaying
})
},
|
上一首
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
|
before: function () {
var that = this
that.setData({
currentIndex: 0,
marginTop: 0,
lrcHeight:200,
})
if (that.data.songIndex == 0) {
that.requestDataSong(that.data.datalist[that.data.datalist.length – 1].song_id)
that.songLrc(that.data.datalist[that.data.datalist.length – 1].song_id)
that.setData({
songIndex: that.data.datalist.length – 1
})
} else {
that.requestDataSong(that.data.datalist[that.data.songIndex – 1].song_id)
that.songLrc(that.data.datalist[that.data.songIndex – 1].song_id)
that.setData({
songIndex: that.data.songIndex – 1
})
}
},
|
歌曲播放
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
playSong: function () {
var that = this
let inv = setInterval(function () {
wx.getBackgroundAudioPlayerState({
success: function (res) {
if (res.status == 1) {
that.setData({
isPlaying: true,
songState: {
progress: res.currentPosition / res.duration * 100,
currentPosition: that.timeToString(res.currentPosition),
duration: that.timeToString(res.duration),
}
})
var i = that.data.currentIndex
if (i < that.data.lry.length) {
if (res.currentPosition – 4 >= parseInt(that.data.lry[0])) {
that.setData({
currentIndex: i + 1
})
}
}
if (that.data.currentIndex >= 6) {
that.setData({
marginTop: -(that.data.currentIndex – 6) * 20,
lrcHeight:200 + (that.data.currentIndex – 6) * 20
})
}
} else {
that.setData({
isPlaying: false
})
clearInterval(inv)
}
}
})
}, 1000)
},
|
|
免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。