微信小程序音频 ,背景音乐

别等时光非礼了梦想. 提交于 2020-03-13 09:50:31
//app.js
onLaunch: function () {
console.log(this)
this.AppMusic = wx.createInnerAudioContext();
this.AppMusic.autoplay = true;
this.AppMusic.loop = true;
this.AppMusic.onPlay(() => {
console.log('开始播放')
})
this.AppMusic.onError((res) => {
console.log(res.errMsg)
console.log(res.errCode)
})
},
 
 
//你要播放的界面,加载音乐链接
// 从60s开始播放
app.AppMusic.seek(60);
app.AppMusic.src = 'http://ovhvevt35.bkt.clouddn.com/photo/%E5%A5%BD%E5%A6%B9%E5%A6%B9%E4%B9%90%E9%98%9F%20-%20%E4%B8%8D%E8%AF%B4%E5%86%8D%E8%A7%81.mp3'
// music
music(e){
let that = this;
let status = e.currentTarget.dataset.status;
if (status){
app.AppMusic.pause();
app.AppMusic.onPause(() => {
console.log('暂停播放');
that.setData({
status: false
})
})
}else{
app.AppMusic.play();
app.AppMusic.onPlay(() => {
console.log('开始播放');
that.setData({
status: true
})
})
}
console.log(e)
 
},
// 上传图片音乐会暂停
upImg(){
wx.chooseImage({
success: function (res) {
var tempFilePaths = res.tempFilePaths
wx.uploadFile({
url: 'https://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址
filePath: tempFilePaths[0],
name: 'file',
formData: {
'user': 'test'
},
success: function (res) {
var data = res.data
//do something
}
})
}
})
},
 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!