开发者社区 问答 正文

web rts 本地混流 pushClient.startMicrophone 失败

web rts 本地混流 pushClient.startMicrophone 失败报:InvalidStateError
是什么原因呢?

快速接入的模式可以,混流模式就不行。


        async getLocalStream() {
            let isMix = true;
            if (!isMix) {
                //快速接入
                this.cameraStreamId = await this.pushClient.startCamera();
                this.micStreamId = await this.pushClient.startMicrophone();
            } else {
                //开启本地混流模式前设置
                this.videoEffectManager.setMixingConfig({
                    videoWidth: this.width,
                    videoHeight: this.height,
                    videoFramerate: 30
                });
                //开启本地混流模式
                this.videoEffectManager.enableMixing(true);
                //判断有没有摄像头可以用,有的话取一个 cameraStreamId
                if (this.cameraList.length > 0) {
                    this.cameraStreamId = await this.pushClient.startCamera(this.cameraList[0].deviceId);
                }
                //设置视频流
                if (this.cameraStreamId != null) {
                    this.videoEffectManager.setLayout([
                        { streamId: this.cameraStreamId, x: (this.width - 24) / 2, y: (this.height - 100) / 2, width: this.width, height: this.height, zOrder: 1 }
                    ]);
                }
                try {
                    //判断有没有麦克风可以用,有的话取一个 micStreamId
                    if (this.micList.length > 0) {
                        this.micStreamId = await this.pushClient.startMicrophone(this.micList[0].deviceId);
                        console.log(this.micStreamId, '取到的要混入的音频流 id')
                    }
                } catch (e) {
                    console.log(e, '采集麦克风失败')
                }
                //设置音频流
                if (this.micStreamId != null) {
                    this.audioEffectManager.setVolume(50, this.micStreamId);
                    this.pushClient.addCustomStream(this.micStreamId);
                }
            }
        },

展开
收起
1548617453250487 2026-02-05 14:14:41 25 分享 版权
来自: 阿里云视频云
0 条回答
写回答
取消 提交回答
问答分类:
CDN
关联地址: