开发者社区 问答 正文

vue 项目中 web aliWebrtc 订阅纯音频流为啥没有声音? 求大神指点

 getAliVoice () {
            var aliWebrtc = this.aliWebrtc;
            //检测浏览器是否支持webrtc
            let options = {
                isReceiveOnly: true,//是否为纯订阅模式。取值:true|false(默认值)
                isDebug: true//线上环境必须使用https协议。您可以添加{isDebug: true}参数进行localhost(本地主机)调试跳过https协议检测。
            };
            aliWebrtc.isSupport(options).then(res => {
                console.log(res, '支持');
                this.init();
            }).catch(error => {
                console.log(error, '不支持RTC');
            })

    }
      init () {
           var aliWebrtc = this.aliWebrtc;
            this.$axios.get(url', {
                params: {
                    channelId: id,
                    userId: userId
                }
            }).then(res => {
                let info = {
                    appid: res.appId,
                    userid: res.userId,
                    timestamp: res.timestamp,
                    nonce: res.nonce,
                    token: res.token,
                    gslb: [res.gslb],
                    channel: res.channelId
                }

                //加入频道
                aliWebrtc.joinChannel(info, 自己的id).then(() => {
                    console.log('加入成功');
                    aliWebrtc.subscribe(推流的id).then((data) => {
                        console.log(data, 'subscribe执行~~~')
                        aliWebrtc.configRemoteAudio(推流的id, true);
                        aliWebrtc.configRemoteCameraTrack(推流的id, false);
                        aliWebrtc.configRemoteScreenTrack(推流的id, false);
                    }).catch(error => {
                        console.log(error.message, 'subscribe错误');
                    });
                }).catch(error => {
                    // 入会失败,打印错误内容,可以看到失败原因
                    console.log(error.message, '加入房间失败');
                });

                //当远程用户推流时,在SDK里会触发onPublisher回调,通过订阅这个回调,能够得到频道里已经推流的用户
                aliWebrtc.on('onPublisher', (data) => {
                    console.log(data, '用户推流')
                })


                //订阅流成功回调。当订阅远程流成功时触发,会返回远程流的Stream对象,通过H5 Video或Audio播放
                aliWebrtc.on('onMediaStream', (subscriber, stream) => {
                    console.log(subscriber, stream, '阅流成功回调');
                    // aliWebrtc.setDisplayRemoteVideo(subscriber, _this.$refs.htmlVideo, stream);
                })
    }

展开
收起
d5wrgb3albrzo 2021-05-26 18:00:08 1017 分享 版权
1 条回答
写回答
取消 提交回答
  • 经过多次测试 发现在安卓设备上发布的音频流 ,PC上可以播放 而ios设备上发布的音频流却无法订阅

                    //当远程用户推流时,在SDK里会触发onPublisher回调,通过订阅这个回调,能够得到频道里已经推流的用户
                    aliWebrtc.on('onPublisher', () => {
                        console.log('用户推流--- onPublisher')
                        //订阅远程流
                        aliWebrtc.subscribe(.userId).then(() => {
                            console.log('订阅远程流成功~')
                            aliWebrtc.setDisplayRemoteVideo(buserId, this.$refs.htmlVideo, 1);
                        }).catch(error => {
                            console.log(error.message, '订阅错误回调');
                        });
                    })
    

    这个回调没有触发
    有没有打

    2021-05-28 10:51:38
    赞同 展开评论
问答分类:
问答地址: