uni-app 【报Bug】uni.chooseVideo(OBJECT) 和 uni.getVideoInfo(OBJECT) 获取视频信息错误

uni-app 【报Bug】uni.chooseVideo(OBJECT) 和 uni.getVideoInfo(OBJECT) 获取视频信息错误

产品分类

  • uniapp/H5

PC开发环境操作系统

  • Windows

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

  • 10

HBuilderX类型

  • 正式

HBuilderX版本号

  • 3.2.2

浏览器平台

  • UC浏览器

浏览器版本

  • V13.5.3.1133

项目创建方式

  • HBuilderX

示例代码

uni.chooseVideo({  
    count: 1,  
    sourceType: ['camera'],  
    maxDuration: Math.floor(_this.nextRule.videoTime),  
    success: function(res) {  
        console.log(res);  
        uni.getVideoInfo({  
            src: res.tempFilePath,  
            success: (videoInfo) => {  
                _this.nextRule.videoSrc = res.tempFilePath;  
                _this.nextRule.videoInfo = res.tempFile;  
                let duration = _this.nextRule.videoTime  
                console.log(duration, videoInfo)  
                if (videoInfo.duration < duration) {  
                    uni.hideLoading()  
                    uni.showToast({  
                        icon: "none",  
                        title: "视频时长不够" + duration + "秒,请重新拍摄",  
                        duration: 3000,  
                    })  
                } else {  
                    _this.$refs.uploadRef.handleChange(res.tempFile);  
                }  
            }  
        })  

    },  
    fail(e) {  
        _this.showPhotoCheckBtn = false;  
        console.log(e);  
    }  
});

操作步骤

  • 手机uc浏览器 使用api拍摄视频

预期结果

  • duration参数为0不可用,结果需要为视频真实的时间长度

实际结果

  • 视频时长为5秒
  • duration参数值为5

bug描述

Hbuilder版本:3.2.2.20210818
浏览器:uc浏览器 V13.5.3.1133
api:uni.getVideoInfo(OBJECT)
uni.chooseVideo(OBJECT)
问题:success返回参数duration 为0

Image


更多关于uni-app 【报Bug】uni.chooseVideo(OBJECT) 和 uni.getVideoInfo(OBJECT) 获取视频信息错误的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于uni-app 【报Bug】uni.chooseVideo(OBJECT) 和 uni.getVideoInfo(OBJECT) 获取视频信息错误的实战教程也可以访问 https://www.itying.com/category-93-b0.html


根据您提供的代码和问题描述,这是一个已知的兼容性问题。在UC浏览器中,uni.getVideoInfo 获取视频信息时,duration 参数可能返回0,这是由于浏览器对视频元数据解析的支持不一致导致的。

原因分析: UC浏览器在处理某些视频格式或编码时,可能无法正确读取视频的时长信息。uni.getVideoInfo 依赖于浏览器的底层API来解析视频元数据,而UC浏览器在这方面存在兼容性限制。

解决方案:

  1. 优先使用 uni.chooseVideo 返回的时长信息
    在您的代码中,uni.chooseVideosuccess 回调已返回 res.duration,这是视频的实际时长。建议直接使用这个值,无需再调用 uni.getVideoInfo 获取时长。修改代码如下:

    uni.chooseVideo({  
        count: 1,  
        sourceType: ['camera'],  
        maxDuration: Math.floor(_this.nextRule.videoTime),  
        success: function(res) {  
            console.log(res);  
            _this.nextRule.videoSrc = res.tempFilePath;  
            _this.nextRule.videoInfo = res.tempFile;  
            let duration = _this.nextRule.videoTime;  
            console.log(duration, res.duration);  
            if (res.duration < duration) {  
                uni.hideLoading();  
                uni.showToast({  
                    icon: "none",  
                    title: "视频时长不够" + duration + "秒,请重新拍摄",  
                    duration: 3000,  
                });  
            } else {  
                _this.$refs.uploadRef.handleChange(res.tempFile);  
            }  
        },  
        fail(e) {  
            _this.showPhotoCheckBtn = false;  
            console.log(e);  
        }  
    });
回到顶部