Page({ data:{ item:0, tab:0 }, changeTab:function(e){ this.setData({ tab:e.detail.current }) }, changeItem:function (e) { this.setData({ item: e.target.dataset.item }) } }) playlist:[{ id:1, title:'祝你生日快乐', singer:'小丽', src:'http://127.0.0.1:3000/1.mp3', coverImgUrl:'/images/cover.jpg' },{ id:2, title:'劳动最光荣', singer:'小明', src:'http://127.0.0.1:3000/1.mp3', coverImgUrl:'/images/cover.jpg' },{ id:3, title:'龙的传人', singer:'小华', src:'http://127.0.0.1:3000/1.mp3', coverImgUrl:'/images/cover.jpg' },{ id:4, title:'小星星', singer:'小红', src:'http://127.0.0.1:3000/1.mp3', coverImgUrl:'/images/cover.jpg' },{ }], audioBam:null, onReady:function(){ this.audioBam=wx.getBackgroundAudioManager() //默认选择第一种 this.setMusic(0) }, setMusic:function(index){ //设置当前播放的曲目,在后面的步骤中实现 } setMusic:function(index){ var music =this.data.playlist[index] this.audioBam.src=music.src this.audioBam.title=music.title this.setData({ playIndex:index, 'play.title':music.title, 'play.singer':music.singer, 'play.coverImgUrl':music.coverImgUrl, "playcurrentTime":'00:00', "play.duration":'00:00', "play.percent":'0', state:'running' }) play:function(){ this.audioBam.play() this.setData({ state:'running' }) } pause:function(){ this.audioBam.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) } }