uni-app uni.chooseVideo在安卓系统华为手机上无法返回tempFile结果报undefined
uni-app uni.chooseVideo在安卓系统华为手机上无法返回tempFile结果报undefined
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Mac | 10.15.4 | HBuilderX |
# 操作步骤:
```javascript
//获取本地视频
select_video(){
var _this = this;
uni.chooseVideo({
maxDuration:30, //拍摄视频最长拍摄时间,单位秒
count:1, //上传视频的数量
sourceType:['camera','album'],
success: (res) => {
console.log(res.tempFilePath)
console.log(res.tempFile)
_this.preview_video = res.tempFilePath;
_this.video_src = res.tempFile;
_this.file_name = _this.video_src.name;
// console.log(_this.preview_video)
// console.log(_this.video_src)
_this.selected = true;
_this.is_video = 1;
}
})
},
预期结果:
预期可以拿到tempFile的返回结果
实际结果:
拿不到
bug描述:
uni.chooseVideo在真机选择图片后,返回结果只有tempFilePath是正确的,附带更多信息的tempFile都是undefined。
//获取本地视频
select_video(){
var _this = this;
uni.chooseVideo({
maxDuration:30, //拍摄视频最长拍摄时间,单位秒
count:1, //上传视频的数量
sourceType:['camera','album'],
success: (res) => {
console.log(res.tempFilePath)
console.log(res.tempFile)
_this.preview_video = res.tempFilePath;
_this.video_src = res.tempFile;
_this.file_name = _this.video_src.name;
// console.log(_this.preview_video)
// console.log(_this.video_src)
_this.selected = true;
_this.is_video = 1;
}
})
},
控制台信息: 19:00:05.084 App Hide at App.vue:10 19:00:08.320 App Show at App.vue:7 19:00:08.410 file:///storage/emulated/0/Pictures/Screenshots/SVID_20200421_222327_1.mp4 at pages/release/release.vue:168 19:00:08.435 undefined at pages/release/release.vue:169 19:00:08.459 TypeError: undefined is not an object (evaluating ‘_this.video_src.name’)
更多关于uni-app uni.chooseVideo在安卓系统华为手机上无法返回tempFile结果报undefined的实战教程也可以访问 https://www.itying.com/category-93-b0.html
success 返回参数说明
参数 类型 说明 平台差异说明说明
tempFilePath String 选定视频的临时文件路径
tempFile File 选定的视频文件 仅H5(2.6.15+)支持
更多关于uni-app uni.chooseVideo在安卓系统华为手机上无法返回tempFile结果报undefined的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这是一个已知的兼容性问题,uni.chooseVideo在部分安卓机型上确实不会返回tempFile对象。建议改用以下解决方案:
- 首先确认tempFilePath是否存在:
if(res.tempFilePath){
// 使用tempFilePath获取文件信息
}
- 如果需要获取文件信息,可以通过plus.io.resolveLocalFileSystemURL实现:
plus.io.resolveLocalFileSystemURL(res.tempFilePath, function(entry){
entry.file(function(file){
console.log(file.name); // 文件名
console.log(file.size); // 文件大小
console.log(file.type); // 文件类型
});
});
- 或者使用uni.getFileInfo获取基本信息:
uni.getFileInfo({
filePath: res.tempFilePath,
success: (info) => {
console.log(info.size);
}
});