uni-app 最新版本Hbuild X app端选择视频严重bug 返回临时文件路径头部缺少file://

uni-app 最新版本Hbuild X app端选择视频严重bug 返回临时文件路径头部缺少file://

开发环境 版本号 项目创建方式
Windows HBuilderX

产品分类:uniapp/App

PC开发环境操作系统:Windows

PC开发环境操作系统版本号:windows10

HBuilderX类型:正式

HBuilderX版本号:3.1.11

手机系统:Android

手机系统版本号:Android 11

手机厂商:一加

手机机型:8t

页面类型:vue

打包方式:云端

示例代码:

uni.chooseVideo({  
    count: 1,  
    sourceType: ['camera', 'album'],  
    success: (res) => {  
        console.log(videoSrc)  
        // 返回的是 /storage/emulated/0/Android/data/com.aaaa.zz/apps/__UNI__1111111/temp/compress_video_1318007382.mp4  
        // 应该返回 file:///storage/emulated/0/Android/data/com.aaaa.zz/apps/__UNI__1111111/temp/compress_video_1318007382.mp4  
    }  
});

操作步骤:

执行uni.chooseVideo 接口选择一个视频

预期结果:

新版本hbuildx uni.chooseVideo接口 选择视频后返回临时文件路径头部加上file:// 和之前的版本一致,且上传视频后不要模糊

实际结果:

新版本hbuildx uni.chooseVideo接口 选择视频后返回临时文件路径头部缺少file:// 导致直接执行上传文件会失败,且上传视频后很模糊

bug描述:

新版本hbuildx uni.chooseVideo接口 选择视频后返回临时文件路径头部缺少file://,导致上传视频时会失败,之前的某个版本正常。 选择图片也是正常的 前面拼接上file://后可以上传了,但是上传后视频变得很模糊


更多关于uni-app 最新版本Hbuild X app端选择视频严重bug 返回临时文件路径头部缺少file://的实战教程也可以访问 https://www.itying.com/category-93-b0.html

21 回复

选择图片返回的临时路径是正确的

更多关于uni-app 最新版本Hbuild X app端选择视频严重bug 返回临时文件路径头部缺少file://的实战教程也可以访问 https://www.itying.com/category-93-b0.html


拼接上file://可以上传了,但是视频变的很模糊

模糊是开了视频压缩 可以关闭具体看chooseVideo 设置compressed

设置compressed后选择视频就失效了

回复 DCloud_Android_ST: 麻烦测试下chooseVideo 设置compressed属性后选择视频后没有回调参数的问题,并和这个问题一块修复,并且目前视频压缩过于模糊了,和微信小程序对比了下,微信小程序的视频压缩后后比app压缩后的要小,但是比app上要清晰,app上压缩的体积没少多少,但是却很模糊,并且压缩后视频的尺寸也变的比原视频大很多

回复 拓荒: 加一下我qq 643833712. 我试一下你说的压缩尺寸的问题

我的也出现这个问题现在不知道怎么上传了,如果现在加上file://,后面上线还用不用改回来?没上传之前临时路径播放确实是很模糊。

可以先判定一下反馈路径是否为“/storage”开头的路径 是的话加上file://

回复 DCloud_Android_ST: 加上了判断发现现在也不能预览显示,一开始可以预览现在预览都不能预览?

回复 请输入这个昵称: 什么预览 视频预览?

回复 DCloud_Android_ST: 是视频预览,我把路径直接给video了,不显示

回复 请输入这个昵称: 你可以提供一个完整示例我们测试下看看 或者等发版修复问题再试试看

回复 DCloud_Android_ST: 代码写在评论区了,想问什么时候发版比较急用这个

回复 请输入这个昵称: 问题已经确认了。会尽快修复

chooseVideo: function() {
let that = this;
uni.chooseVideo({
success: (res) => {
console.log(res)
if(res.tempFilePath.indexOf(’/storage’)==0){

                        that.imageList.push('file://'+res.tempFilePath);  
                    }else{  
                        that.imageList.push(res.tempFilePath);  
                    }  
                    that.imagetype.push(2);  
                    console.log('打印出来',that.imageList)  
                },  
                fail: (err) =>   
                {  
                }  
            })  
        }  
<block v-for="(image,index) in imageList" :key="index"> <view class="uni-uploader__file"> <view class="icon-del" :data-index='index' @click="delimageList"></view> </view> </block>

你说的预览图,是指下面黑色的区域应该有视频预览吗。 这个需要手动设置 poster属性实现

我指的是播放点击不能那个播放

回复 请输入这个昵称: 我回复在下面了。 你对比一下

下面是hello uni代码,添加了file:// 之后可以正常使用。你对比一下。
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-common-mt">
<view class="uni-list">
<view class="uni-list-cell">
<view class="uni-list-cell-left">
<view class="uni-label">视频来源</view>
</view>
<view class="uni-list-cell-right">
<picker :range=“sourceType” @change=“sourceTypeChange” :value=“sourceTypeIndex”>
<view class="uni-input">{{sourceType[sourceTypeIndex]}}</view>
</picker>
</view>
</view>
</view>
</view>

<view class="uni-title uni-common-mt uni-common-pl">摄像头位置</view>
<view class="uni-hello-text camera-tips">注意:部分 Android 手机下由于系统 ROM 不支持无法生效,打开拍摄界面后可操作切换</view>
<view class="uni-list">
<radio-group @change=“radioChange”>
<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in cameraList" :key="item.value">
<radio :value="item.value" :checked="index === cameraIndex">{{item.name}}</radio>
</label>
</radio-group>
</view>

<template v-if="!src">
<view class=“uni-hello-addfile” @tap=“chooseVideo”>+ 添加视频</view>
</template>
<template v-else>

</template>
</view>
</template>

<script> var sourceType = [ ['camera'], ['album'], ['camera', 'album'] ] export default { data() { return { title: 'chooseVideo', sourceTypeIndex: 2, sourceType: ['拍摄', '相册', '拍摄或相册'], src: '', cameraList: [{ value: 'back', name: '后置摄像头', checked: 'true' }, { value: 'front', name: '前置摄像头' }, ], cameraIndex: 0 } }, onUnload() { this.src = '', this.sourceTypeIndex = 2, this.sourceType = ['拍摄', '相册', '拍摄或相册']; }, methods: { radioChange(evt) { for (let i = 0; i < this.cameraList.length; i++) { if (this.cameraList[i].value === evt.detail.value) { this.cameraIndex = i; break; } } }, sourceTypeChange: function(e) { this.sourceTypeIndex = parseInt(e.detail.value) }, chooseVideo: function() { uni.chooseVideo({ camera: this.cameraList[this.cameraIndex].value, sourceType: sourceType[this.sourceTypeIndex],Q success: (res) => { this.src = "file://" + res.tempFilePath }, fail: (err) => { // #ifdef MP uni.getSetting({ success: (res) => { let authStatus = false; switch (this.sourceTypeIndex) { case 0: authStatus = res.authSetting['scope.camera']; break; case 1: authStatus = res.authSetting['scope.album']; break; case 2: authStatus = res.authSetting['scope.album'] && res.authSetting['scope.camera']; break; default: break; } if (!authStatus) { uni.showModal({ title: '授权失败', content: 'Hello uni-app需要从您的相机或相册获取视频,请在设置界面打开相关权限', success: (res) => { if (res.confirm) { uni.openSetting() } } }) } } }) // #endif } }) } } } </script> <style> .video { width: 100%; } .camera-tips { padding: 10rpx 30rpx; } </style>

这样拼接file://有问题,之前就是这样拼接的,现在发现拍摄的视频前面不能加file://。

这是一个已知的HBuilderX 3.1.11版本中的兼容性问题。在Android 11设备上,uni.chooseVideo接口返回的临时文件路径确实缺少了file://前缀,这会导致后续文件上传操作失败。

问题分析:

  1. 路径格式问题:返回的本地文件路径应该是file://开头的URI格式,但当前版本返回的是纯文件路径
  2. 视频模糊问题:可能是压缩参数导致的画质损失

临时解决方案:

uni.chooseVideo({  
    count: 1,  
    sourceType: ['camera', 'album'],
    compressed: false, // 禁用压缩以避免模糊问题
    success: (res) => {  
        // 手动添加file://前缀
        const videoPath = 'file://' + res.tempFilePath;
        console.log(videoPath);
        // 使用处理后的路径进行上传
    }  
});
回到顶部