Page({ /** * 页面的初始数据 */ data: { item:0, tab:0, // 播放器列表数据 playlist:[{ id:1, title:"晴天", singer:'周杰伦', src:'http://localhost:3000/1.mp3', converImgUrl:'../images/yhm.png' },{ id:2, title:"反方向的钟", singer:'周杰伦', src:'http://localhost:3000/2.mp3', converImgUrl:'../images/yhm.png' },{ id:3, title:"兰亭序", singer:'周杰伦', src:'http://localhost:3000/3.mp3', converImgUrl:'../images/yhm.png' },{ id:4, title:"青花瓷", singer:'周杰伦', src:'http://localhost:3000/4.mp3', converImgUrl:'../images/yhm.png' },{ id:5, title:"本草纲目", singer:'周杰伦', src:'http://localhost:3000/4.mp3', converImgUrl:'../images/yhm.png' },{ id:6, title:"爱在西元前", singer:'周杰伦', src:'http://localhost:3000/4.mp3', converImgUrl:'../images/yhm.png' },{ id:7, title:"花海", singer:'周杰伦', src:'http://localhost:3000/4.mp3', converImgUrl:'../images/yhm.png' },{ id:8, title:"半岛铁盒", singer:'周杰伦', src:'http://localhost:3000/4.mp3', converImgUrl:'../images/yhm.png' },{ id:9, title:"轨迹", singer:'周杰伦', src:'http://localhost:3000/4.mp3', converImgUrl:'../images/yhm.png' },{ id:10, title:"搁浅", singer:'周杰伦', src:'http://localhost:3000/4.mp3', converImgUrl:'../images/yhm.png' } ], state:'paused', playIndex:0, play:{ currentTime:'00:00', duration:'00:00', percent:0, title:'', singer:'', // converImgUrl:'../images/cover.jpg' coverImgUrl:'../images/yhm.png' } }, audioCtx:null, changeItem(e){ this.setData({ item : e.target.dataset.item }) }, changeTab(e){ this.setData({ tab:e.detail.current }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { this.audioCtx = wx.createInnerAudioContext(); this.setMusic(0); }, setMusic(index){ var music = this .data.playlist[index]; this.audioCtx.src = music.src; this.setData({ playIndex: index, 'play.title': music.title, 'play.singer': music.singer, 'play.coverImgUrl': music.coverImgUrl, 'play.currentTime': '00:00', 'play.duration': '00:00', 'play.percent': 0 }) }, // 播放 play: function() { this.audioCtx.play(); this.setData({state: 'running'}) }, // 暂停 pause: function () { this.audioCtx.pause(); this.setData({state: 'paused'}); }, // 下一曲 next: function() { var index = this.data.playIndex >= this.data.playlist.length - 1 ? 0 : this.data.playIndex + 1 this. setMusic(index) if (this .data.state == 'running') { this.play() } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })