年前寫的demo,年假家里沒有網(wǎng),就放下了..回來這幾天抓緊時(shí)間完善了下.分享給大家哦,(歌詞動(dòng)態(tài)展示待優(yōu)化),還有電臺(tái)那里的接口暫時(shí)沒有找到.找到后我再添加上去,新的一年,大家一起努力哦!,新年第一帖主要功能:歌曲暫 ...
年前寫的demo,年假家里沒有網(wǎng),就放下了..回來這幾天抓緊時(shí)間完善了下.分享給大家哦,(歌詞動(dòng)態(tài)展示待優(yōu)化),還有電臺(tái)那里的接口暫時(shí)沒有找到.找到后我再添加上去,新的一年,大家一起努力哦!,新年第一帖主要功能:
歌曲暫停播放
上一首
下一首
當(dāng)前歌曲播放完成后自動(dòng)播放下一首
歌詞動(dòng)態(tài)展示
效果圖:
暫停/播放
playAndPause: function () {
var that = this
if (that.data.isPlaying) {
wx.pauseBackgroundAudio()
} else {
wx.playBackgroundAudio()
}
that.playSong()
that.setData({
isPlaying: !that.data.isPlaying
})
},
上一首
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
})
}
},
歌曲播放
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)
工作日 8:30-12:00 14:30-18:00
周六及部分節(jié)假日提供值班服務(wù)