发布于 

uniapp,保存视频到相册

uniapp,保存视频到相册,安卓端是正常的,ios端下载成功,在把文件塞进相册的时候却一直失败。

找了好几个解决方案最后才定位问题,下载下来的视频是flv格式的,把视频变成mp4格式的就成功了,估计是ios不认为flv是一个视频文件,所以不让进相册

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
uni.showModal({
title: "提示",
content: "是否下载该视频",
showCancel: true,
cancelText: '取消',
confirmText: '下载',
success: res => {

if (res.confirm) {
// 用户点击确定
that.downvideo = true
const downloadTask = uni.downloadFile({
url: encodeURI(`${apiUrl}` +
'/api/downvideo-web/downVideo/likeVideo?dangerId=' + that.id +
'&&groupId=' + header().groupId),
header: header(),
success: (data) => {
if (data.statusCode === 200) {

if (uni.getSystemInfoSync().platform == 'ios')
data.tempFilePath = escape(data.tempFilePath)

filePath: data.tempFilePath, // 视频的本地临时地址
success: function(res) {
uni.showToast({
title: '下载完成,请到相册查看',
position: 'center',
icon: 'none',
duration: 2000
});
},
fail: (err) => {
uni.showToast({
title: err,
position: 'center',
icon: 'none',
duration: 2000
});
},
complete: () => {
that.downvideo = false
that.videoprogress = 0
}
});
}
},
fail: (err) => {
uni.hideLoading()
uni.showToast({
title: err || '未开通或没有权限',
position: 'center',
icon: 'none',
duration: 2000
});
},
complete: () => {
that.downvideo = false
that.videoprogress = 0
}
});

downloadTask.onProgressUpdate((res) => { // 下载进度
// console.log('进度=' + res.progress)
if (this.videoprogress < 100) {
this.videoprogress = res.progress
}
});
}
}
})