l***@gmail.com
l***@gmail.com
  • 发布:2021-09-27 17:31
  • 更新:2023-05-05 10:12
  • 阅读:843

【报Bug】uni.createInnerAudioContext()的onCanplay监听失效

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

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

HBuilderX类型: 正式

HBuilderX版本号: 3.2.9

手机系统: Android

手机系统版本号: Android 7.1.1

手机厂商: 模拟器

手机机型: 逍遥模拟器,夜神模拟器,nubia Z17手机

页面类型: nvue

打包方式: 离线

项目创建方式: HBuilderX

示例代码:

父页面调用组件

<recordingVoice :recordingVoiceShow.sync="recordingVoiceShow" :recordingUrl.sync="recordingUrl"></recordingVoice>  

<playVoice v-if="(this.recordingUrl == '')?false:true" class="recordingSoundsPath" playType="user" :path.sync="recordingUrl" :recordingTrans.sync="recordingTranslation"></playVoice>

recordingVoice组件部分代码

    mounted() {  
        //录音开始监听  
        this.recorderManager.onStart(() => {  
            this.timer = setInterval(() => {  
                this.times++;  
            }, 1000);  
        });  
        //录音停止后将音频临时文件地址发给父组件  
        this.recorderManager.onStop(res => {  
            console.log(res);  
            clearInterval(this.timer);  
            //录音结束后将音频临时地址暴露出去  
            this.$emit('update:recordingUrl', res.tempFilePath);  
            this.$emit('update:recordingVoiceShow', false);  
        });  
    }

playVoice组件部分代码

    watch: {  
        path: {  
            immediate: true,  
            handler: function(newVal) {  
                if (newVal) {  
                    console.log(newVal)  
                    this.voicePath = newVal;  
                    this.innerAudioContext.src = newVal;  
                    //音频时长  
                    this.innerAudioContext.onCanplay(() => {  
                        console.log(this.innerAudioContext.duration);  
                        this.allTime = 0;  
                        this.allTime = this.timeChange(this.innerAudioContext.duration.toFixed(0));  
                    });  
                }  
            }  
        }  
    },

操作步骤:

1,页面第一次加载默认显示recordingVoice组件,playVoice组件通过v-if隐藏。
2,此时用户录音,recordingVoice将res.tempFilePath传到父页面,recordingVoice通过v-if控制消失,playVoice组件出现,并通过监听res.tempFilePath的方式,将res.tempFilePath赋值给recordingVoice组件,this.innerAudioContext.src = newVal,此时onCanplay监听生效,得到音频时长。
3,用户删除playVoice组件,this.innerAudioContext.destroy();this.$emit('update:path', '');playVoice组件消失,recordingVoice组件重现。
此时再执行1,2两步骤,onCanplay监听失效,无法监听。

预期结果:

onCanplay监听可以一直正常生效

实际结果:

onCanplay监听在第二次无法正常生效

bug描述:

uni.createInnerAudioContext接口第二次读取uni.getRecorderManager接口onStop监听回调中的res.tempFilePath无法触发uni.createInnerAudioContext的onCanplay方法的问题,可以正常播放,但是无法通过onCanplay监听获取到音频文件的duration,onError也没有触发。

2021-09-27 17:31 负责人:无 分享
已邀请:
1***@163.com

1***@163.com

2023年了,这个问题还有

l***@gmail.com

l***@gmail.com (作者)

有官方的人在吗?这不算bug?还是你们无法复现?给个回复啊

要回复问题请先登录注册