1.效果图如下:
2.代码如下:
//index.js//获取应用实例var app = getApp()Page({ data: { motto: 'Hello World', userInfo: {} }, //事件处理函数 bindViewTap: function() { wx.navigateTo({ url: '../logs/logs' }) }, onLoad: function () { console.log('onLoad') var that = this //调用应用实例的方法获取全局数据 app.getUserInfo(function(userInfo){ //更新数据 that.setData({ userInfo:userInfo }) }) }, play: function() { console.log("播放") wx.playBackgroundAudio({ dataUrl: 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&fromtag=46', title: '', coverImgUrl: ''}) }, pause: function() { console.log("暂停") wx.pauseBackgroundAudio({ success: function(res){ // success console.log(res) }, fail: function() { // fail }, complete: function() { // complete } }) }})
详细的可以参看文档学习哟!!!
https://mp.weixin.qq.com/debug/wxadoc/dev/api/media-background-audio.html