小程序视频下载安卓端,pc端,体验版都没问题。ios下载就报错,分享解决办法

代码

复制代码
videos.forEach((url, index) => {
						var filepath = wx.env.USER_DATA_PATH + '/' + new Date().valueOf() + '.mp4'
						uni.downloadFile({
							url: url, //视频的地址
							filePath: filepath,
							header: {
								'content-type': 'application/json'
							},
							success: function(res) {
								console.log(res, '111')
								uni.saveVideoToPhotosAlbum({
									// filePath: modifiedPath,
									filePath: res.filePath,
									success: (ers) => {
										uni.hideLoading();
										setTimeout(() => {
											uni.showToast({
												title: '保存成功'
											});
										}, 600)
									},
									fail: (err) => {
										console.log(err, '444')
										uni.showToast({
											title: '保存失败',
											icon: 'error'
										});
									}
								});
                                 },
							fail: (err) => {
								console.log(err, '1012')
							},
						})
					})

苹果端报错:

后来查了大量资料,找到

一试就成了,视频格式转换可以下载《格式工厂》

,在记录一个安卓苹果都能用的图片下载

复制代码
uni.showLoading({
					title: '素材下载中'
				});
				var image = images
				// 图片下载
				let filename = new Date().getTime() + ".jpg";
				if (images.length > 0) {
					image.forEach((url, index) => {
						let uniqueFilename = new Date().getTime() + "_" + index + ".jpg";
						let filePath = wx.env.USER_DATA_PATH + "/" + uniqueFilename; // 每次生成唯一的文件路径
						uni.downloadFile({
							url: url, //图片的地址
							filePath: filePath,
							success: function(res) {
								uni.saveImageToPhotosAlbum({
									filePath: res.filePath,
									success: (red) => {
										uni.hideLoading();
										setTimeout(() => {
											uni.showToast({
												title: '保存成功'
											});
										}, 600)
									},
									fail: (err) => {
										console.log(err, '000')
										uni.hideLoading();
										uni.showToast({
											title: '保存失败',
											icon: 'error'
										});
									}
								});
							},
							fail: (err) => {
								console.log(err)
							},
						})
					})
				}
相关推荐
00后程序员张19 小时前
iOS 上架费用全解析 开发者账号、App 审核、工具使用与开心上架(Appuploader)免 Mac 成本优化指南
android·macos·ios·小程序·uni-app·cocoa·iphone
来来走走19 小时前
Android开发(Kotlin) 扩展函数和运算符重载
android·开发语言·kotlin
wuwu_q19 小时前
用通俗易懂 + Android 开发实战的方式,详细讲解 Kotlin Flow 中的 retryWhen 操作符
android·开发语言·kotlin
天选之女wow20 小时前
【代码随想录算法训练营——Day60】图论——94.城市间货物运输I、95.城市间货物运输II、96.城市间货物运输III
android·算法·图论
沐怡旸20 小时前
【底层机制】Android对Linux线程调度的移动设备优化深度解析
android·面试
正经教主1 天前
【咨询】Android Studio 第三方手机模拟器对比【202511】
android·ide·android studio
WenGyyyL1 天前
微信小程序开发——第三章:WXML 与 WXSS —— 小程序页面结构与样式设计
微信小程序·小程序
Jomurphys1 天前
网络 - 缓存
android
万岳科技系统开发1 天前
外卖小程序中的高并发处理:如何应对大流量订单的挑战
算法·小程序·开源