https://developers.weixin.qq.com/miniprogram/dev/api/media/video/wx.saveVideoToPhotosAlbum.html
// 微信小程序下载视频
wxVideoQuery() {
let fileName = new Date().valueOf();
wx.downloadFile({
url: this.afterLink,
filePath: wx.env.USER_DATA_PATH + ‘/’ + fileName + ‘.mp4’,
success: res => {
uni.showLoading({
title:‘正在下载…’
})
console.log(‘下载’, res)
let filePath = res.filePath; //下载到本地获取临时路径
wx.saveVideoToPhotosAlbum({ //保存到相册
filePath,
success: file => {
uni.hideLoading()
wx.showToast({
title: ‘保存成功’,
icon: ‘success’,
duration: 3000
})
let fileMgr = wx.getFileSystemManager();
fileMgr.unlink({ //删除临时文件
filePath: wx.env.USER_DATA_PATH + ‘/’ + fileName +
‘.mp4’,
})
},
fail: err => {
console.log(‘保存失败’, err)
if (err.errMsg == ‘saveVideoToPhotosAlbum:fail auth deny’) {
wx.showModal({
title: ‘提示’,
content: ‘需要您授权保存相册’,
showCancel: false,
success: modalSuccess => {
wx.openSetting({
success(settingdata) {
if (settingdata
.authSetting[
‘scope.writePhotosAlbum’
]) {
console.log(
‘获取权限成功,请再次点击保存!’
)
} else {
console.log(
‘获取权限失败,下载视频无法正常使用’
)
}
}
})
}
})
}
}
})
}
})
},