欢迎光临,了解微信小程序开发,就上易用通!

当前位置 : 易用通 > 小程序模板
音乐视屏播放,歌词展示,暂停/播放/上一首/下一首音乐视屏播放,歌词展示,暂停/播放/上一首/下一首
立即下载

音乐视屏播放,歌词展示,暂停/播放/上一首/下一首

模板分类 : 小程序模板 模板编号 : Y279 源码文件 : 完全开源 下载权限 : VIP会员
模板大小 :  模板指数 :  更新时间 : 2018-01-17 10:01 模板等级 : ☆☆☆☆☆

模板截图:

音乐视屏播放,歌词展示,暂停/播放/上一首/下一首(图1) 
关键代 码
暂停/播放
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)
  },
 

加入收藏
立即下载
分享到微信朋友圈
X

免责声明:

1. 本站所有素材(未指定商用),仅限学习交流,请勿用于商业用途。
2. 本站所有小程序模板Demo和图片均来自用户分享上传和网络收集,模板和图片版权归原作者及原出处所有。
3. 未经合法授权,会员不得以任何形式发布、传播、复制、转售该素材。