微信小程序下载视频到相册(带进度条)

微信小程序下载视频到相册,并带进度条

	<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 + "%":'下载中...'
		    })
		},
     }
}


微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条
微信小程序下载视频到相册,并带进度条

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值