uniapp,保存视频到相册


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

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

 1 uni.showModal({
 2                     title: "提示",
 3                     content: "是否下载该视频",
 4                     showCancel: true,
 5                     cancelText: '取消',
 6                     confirmText: '下载',
 7                     success: res => {
 8 
 9                         if (res.confirm) {
10                             // 用户点击确定
11                             that.downvideo = true
12                             const downloadTask = uni.downloadFile({
13                                 url: encodeURI(`${apiUrl}` +
14                                     '/api/downvideo-web/downVideo/likeVideo?dangerId=' + that.id +
15                                     '&&groupId=' + header().groupId),
16                                 header: header(),
17                                 success: (data) => {
18                                     if (data.statusCode === 200) {
19 
20                                         if (uni.getSystemInfoSync().platform == 'ios')
21                                             data.tempFilePath = escape(data.tempFilePath)
22 
23                                             filePath: data.tempFilePath, // 视频的本地临时地址  
24                                             success: function(res) {
25                                                 uni.showToast({
26                                                     title: '下载完成,请到相册查看',
27                                                     position: 'center',
28                                                     icon: 'none',
29                                                     duration: 2000
30                                                 });
31                                             },
32                                             fail: (err) => {
33                                                 uni.showToast({
34                                                     title: err,
35                                                     position: 'center',
36                                                     icon: 'none',
37                                                     duration: 2000
38                                                 });
39                                             },
40                                             complete: () => {
41                                                 that.downvideo = false
42                                                 that.videoprogress = 0
43                                             }
44                                         });
45                                     }
46                                 },
47                                 fail: (err) => {
48                                     uni.hideLoading()
49                                     uni.showToast({
50                                         title: err || '未开通或没有权限',
51                                         position: 'center',
52                                         icon: 'none',
53                                         duration: 2000
54                                     });
55                                 },
56                                 complete: () => {
57                                     that.downvideo = false
58                                     that.videoprogress = 0
59                                 }
60                             });
61 
62                             downloadTask.onProgressUpdate((res) => { // 下载进度  
63                                 // console.log('进度=' + res.progress)
64                                 if (this.videoprogress < 100) {
65                                     this.videoprogress = res.progress
66                                 }
67                             });
68                         }
69                     }
70                 })

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM