3***@qq.com
3***@qq.com
  • 发布:2022-08-25 18:51
  • 更新:2023-05-06 10:42
  • 阅读:349

【报Bug】app音频获取不到duration 同样的文件放在本地可以获取到 接口回来不行

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

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

HBuilderX类型: 正式

HBuilderX版本号: 3.4.18

手机系统: Android

手机系统版本号: Android 11

手机厂商: 华为

手机机型: 荣耀30s

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

操作步骤:
getSrc() {  
            //console.log(this.audio, 'audio')  
            this.innerAudioContext = uni.createInnerAudioContext();  
            this.innerAudioContext.src = this.audio;  
            //this.innerAudioContext.src = this.srcAA;  

            this.innerAudioContext.autoplay = this.autoplay;  
            this.pausedTow = true  

            //console.log(innerAudioContext.paused, '状态')  
            //console.log(innerAudioContext.duration, 'duration')  
            this.innerAudioContext.onPlay(() => {  
                //  console.log('开始播放');  
                //  console.log(innerAudioContext.paused, '状态')  
                this.paused = this.innerAudioContext.paused  
            });  
            this.innerAudioContext.onPause(() => {  
                //console.log('暂停');  
                //console.log(innerAudioContext.paused, '状态')  
                this.paused = this.innerAudioContext.paused  
            });  
            this.innerAudioContext.onCanplay(() => {  
                console.log('onCanplay')  
                let timeid = setInterval(() => {  
                    if (this.innerAudioContext.duration !== 0) {  
                        clearInterval(timeid)  
                        console.log(this.innerAudioContext.duration, 'this.innerAudioContext.duration')  
                        // this.durationStr = this.formatSecond(this.innerAudioContext.duration)  
                        // this.sliderMax = parseInt(this.innerAudioContext.duration)  
                    } else {  
                        console.log(this.innerAudioContext.duration,  
                            'this.innerAudioContext.duration2')  
                    }  
                }, 500)  

            })  
            this.innerAudioContext.onTimeUpdate((res) => {  
                //  console.log('正在播放')  
                const {  
                    currentTime,  
                    duration  
                } = this.innerAudioContext;  
                const currTimeStr = this.formatTime(currentTime);  
                //console.log(duration, 'duration')  
                this.sliderValue = parseInt(currentTime);  
                // 变动的时间  
                this.currentTimeStr = currTimeStr;  
                //进度条最大值  
                this.sliderMax = duration;  
                //总时间  
                this.timeStr = this.formatTime(duration)  
                //  console.log(duration)  
            });  
            this.innerAudioContext.onEnded((res) => {  
                this.paused = this.innerAudioContext.paused  
                this.nextStep()  
                //console.log('播放结束')  
            })  
            this.innerAudioContext.onError((error) => {  
                console.log('error', error)  
            })  
        },

预期结果:

获取到duration

实际结果:

值为0

bug描述:

uni.createInnerAudioContext() 获取不到duration,一直为0。currentTime可以获取到,所以src合法。试了在onCanplay添加定时器,也试了在onTimeUpdate中获取,都获取不到。但是同样的音频文件我下载到本地。可以获取到,求解。是

2022-08-25 18:51 负责人:无 分享
已邀请:
曾小晨

曾小晨

没人解决吗。。。

要回复问题请先登录注册