微信小程序下载视频保存到本地

1..wxml

spanbindtap="handleDownload"data-link="{{video}}"下载视频/spanvideostyle="margin:0auto;"src="{{video}}"/video

2..js

handleDownload(e){letlink=e.currentTarget.dataset.link;letfileName=newDate().valueOf();wx.downloadFile({url:link,filePath:wx.env.USER_DATA_PATH+'/'+fileName+'.mp4',success:res={console.log(res);letfilePath=res.filePath;wx.saveVideoToPhotosAlbum({filePath,success:file={$Message({content:'下载成功',type:'success'})letfileMgr=wx.getFileSystemManager();fileMgr.unlink({filePath:wx.env.USER_DATA_PATH+'/'+fileName+'.mp4',success:function(r){},})},fail:err={console.log(err)if(err.errMsg==='saveVideoToPhotosAlbum:failauthdeny'){wx.showModal({title:'提示',content:'需要您授权保存相册',showCancel:false,success:data={wx.openSetting({success(settingdata){if(settingdata.authSetting['scope.writePhotosAlbum']){wx.showModal({title:'提示',content:'获取权限成功,再次点击下载即可保存',showCancel:false,})}else{wx.showModal({title:'提示',content:'获取权限失败,将无法保存到相册哦~',showCancel:false,})}},})}})}}})}})},

3.有什么问题欢迎评论留言,我会及时回复你的

TAG标签: 微信小程序下载视频保存到本地微信小程序上的视频怎样下载如何下载微信小程序

http://www.xiaochengxub.com/read-96936.html