wx.showLoading({
title: '正在下载',
icon: 'none',
duration: 10 * 60 * 1000
});
const downloadTask = wx.downloadFile({
url: `https://f.kukahome.com/20210316-152630-28612..mp4`,
success: res => {
wx.saveVideoToPhotosAlbum({
filePath: res.tempFilePath,
success: () => {
wx.showModal({
title: '提示',
content: '视频已保存到手机',
showCancel: false
});
},
fail: err => {
if (err.errMsg.indexOf('auth') > -1) {
wx.showModal({
title: '提示',
content: '需要您授权相册权限后才能保存,请打开权限',
showCancel: false,
confirmText: '好',
success: res => {
wx.openSetting();
}
});
return;
}
if (err.errMsg.indexOf('cancel') > -1) {
wx.showToast({
title: '您取消了保存',
icon: 'none'
});
return;
}
wx.showModal({
title: '提示',
content: JSON.stringify(err)
});
}
});
}
});
downloadTask.onProgressUpdate(res => {
wx.showToast({
title: `下载进度:${res.progress}%`,
icon: 'loading',
duration: 10 * 60 * 1000
})
if (res.progress >= 100) {
wx.hideToast();
downloadTask.offProgressUpdate();
}
});