微信小程序下载视频到相册,并带进度条
<button class="desc-note my-button u-font-32" @click="toUpload(video)" style="color:#1975F7;display: inline-block">
下载视频
</button>
<script>
export default {
methods:{
//下载视频
async toUpload(url){
this.getDownVideo(url)
},
getDownVideo(url){
// 自定义 文件名称
uni.showLoading({
mask:true,
title:'下载中...'
})
let fileName = new Date().valueOf();
const task = uni.downloadFile({
url: url,
filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.mp4', // 拼接本地文件路径
success: (res) => {
let filePath = res.filePath
uni.saveVideoToPhotosAlbum({
filePath,
success:(res) => {
uni.showToast({
title: '下载成功',
icon: 'success',
})
let fileMgr = wx.getFileSystemManager();
// 删除本地文件
fileMgr.unlink({
filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.mp4',
success: function(r) {
console.log('unlink-getFileSystemManager')
console.log(r)
},
})
},
fail(err){
uni.showToast({
title: '保存失败',
icon: 'none',
})
},
complete(res) {
console.log('saveVideoToPhotosAlbum-complete')
console.log(res)
}
})
},
fail(err){
uni.showToast({
title: '下载失败,请稍后再试',
icon: 'none',
})
},
complete(res) {
console.log('downloadFiledownloadFiledownloadFiledownloadFiledownloadFile')
console.log(res)
uni.hideLoading()
}
})
task.onProgressUpdate(this.onProgress)
},
// 提示下载进度
onProgress(res){
uni.showLoading({
mask:true,
title: res.progress?'下载中'+res.progress + "%":'下载中...'
})
},
}
}
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条