admin管理员组文章数量:1640019
微信小程序下载视频保存到本地
.wxml
<span bindtap="handleDownload" data-link="{{video}}">下载视频</span>
<video style="margin: 0 auto;" src="{{video}}"></video>
.js
handleDownload(e) {
let link = e.currentTarget.dataset.link;
let fileName = new Date().valueOf();
wx.downloadFile({
url: link,
filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.mp4',
success: res => {
console.log(res);
let filePath = res.filePath;
wx.saveVideoToPhotosAlbum({
filePath,
success: file => {
wx.showToast({
title: '下载成功',
icon: 'success',
duration: 2000
})
let fileMgr = wx.getFileSystemManager();
fileMgr.unlink({
filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.mp4',
success: function (r) {
},
})
},
fail: err => {
console.log(err)
if (err.errMsg === 'saveVideoToPhotosAlbum:fail auth deny') {
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,
})
}
},
})
}
})
}
}
})
}
})
},
有什么问题欢迎评论留言,我会及时回复你的
版权声明:本文标题:微信小程序下载视频保存到本地 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1726541380a1074756.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论