Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
chooseImage: () => {
wx.chooseImage({
count:2,
sizeType:['original'],
sourceType:['album'],
success: function (res) {
console.log("选择文件完成",res);
},
})
},
previewImage: () => {
wx.previewImage({
urls: ['https://postimg.aliavv.com/newmbp/1cevf.png'],
})
},
getImageInfo: () => {
wx.getImageInfo({
src: 'http://222.178.203.72:19005/whst/63/=onrshlfzZkhZuuzbnl//newmbp/1cevf.png',
success: (res) => {
console.log("获取文件信息完成",res)
}
})
},
saveImageToPhotosAlbum: () => {
wx.downloadFile({
url: 'http://222.178.203.72:19005/whst/63/=onrshlfzZkhZuuzbnl//newmbp/1cevf.png',
success: (res) => {
console.log("文件下载完成", res);
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: (res) => {
console.log("文件保存完成",res);
}
})
}
})
},
startRecord: () => {
wx.startRecord({
success: (res) => {
console.log("开始录音", res);
}
})
setTimeout(function () {
//结束录音
wx.stopRecord()
}, 10000)
},
getRecorderManager: () => {
var recordMger = wx.getRecorderManager()
recordMger.start();
setTimeout(function () {
//结束录音
recordMger.stop();
}, 3000);
recordMger.onStop((res) => {
console.log(res);
})
},
playVoice: () => {
wx.startRecord({
success: function (res) {
var tempFilePath = res.tempFilePath
console.log("开始播放")
wx.playVoice({
filePath: tempFilePath,
success:function(res){
console.log("播放成功", res)
},
complete: function (res) {
console.log("播放完成",res)
}
})
}
})
setTimeout(function () {
//结束录音
wx.stopRecord()
}, 1000)
},
pauseVoice: () => {
wx.pauseVoice()
},
stopVoice: () => {
wx.stopVoice()
},
getBackgroundAudioPlayerState: () => {
wx.getBackgroundAudioPlayerState({
success: function (res) {
console.log("[播放器状态]",res);
},
fail:function(err){
console.log("[播放器失败]",err);
}
})
},
playBackgroundAudio: () => {
wx.playBackgroundAudio({
dataUrl: 'http://222.178.203.72:19005/whst/63/_vrzrsqdZlzppltrhbzppzbnl//M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46',
title: '网易云课堂',
coverImgUrl: 'http://222.178.203.72:19005/whst/63/_xzfshlfzbm//music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000',
success: function (res) {
console.log("[播放成功]",res);
}
})
wx.onBackgroundAudioPlay(() => {
console.log("+++开始播放+++")
})
},
pauseBackgroundAudio: () => {
wx.pauseBackgroundAudio();
wx.onBackgroundAudioPause(() => {
console.log("+++暂停成功+++")
})
},
seekBackgroundAudio: () => {
wx.seekBackgroundAudio({
position: 12,
success: function (res) {
console.log("[调整成功]", res)
},
fail: function (res) { },
complete: function (res) { },
})
},
stopBackgroundAudio: () => {
wx.stopBackgroundAudio()
wx.onBackgroundAudioStop(() => {
console.log("+++停止成功+++")
})
},
getBackgroundAudioManager: () => {
var backgroundAudioManager = wx.getBackgroundAudioManager();
backgroundAudioManager.title = '此时此刻'
backgroundAudioManager.epname = '此时此刻'
backgroundAudioManager.singer = '许巍'
backgroundAudioManager.coverImgUrl = 'http://222.178.203.72:19005/whst/63/_xzfshlfzbm//music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000'
backgroundAudioManager.src = 'http://222.178.203.72:19005/whst/63/_vrzrsqdZlzppltrhbzppzbnl//M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46' // 设置了 src 之后会自动播放
},
createInnerAudioContext:()=>{
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.startTime = 12
innerAudioContext.loop = true
innerAudioContext.obeyMuteSwitch = false
innerAudioContext.volume = 0.5
innerAudioContext.src = 'http://222.178.203.72:19005/whst/63/_vrzrsqdZlzppltrhbzppzbnl//M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
innerAudioContext.onPlay(() => {
console.log('开始播放')
})
innerAudioContext.onError((res) => {
console.log(res.errMsg)
console.log(res.errCode)
})
}
})