【问题标题】:Video steaming recived but not playing in WebRTC已收到视频流但未在 WebRTC 中播放
【发布时间】:2015-01-13 08:49:53
【问题描述】:

我正在尝试使用 WebRTC 创建音频广播应用。为了使其与 IE 兼容,我使用了来自 Attlasian 的 Teamsys 插件。

在互联网上提供的大多数演示中,我在一个页面上看到了两个音频/视频控件。但我正在尝试使用两页应用程序。一个用于发送者,另一个用于接收者。

我正在使用 XHR 将我的流描述发送到数据库,在该数据库中,另一个用户接收它并用作接收端对等连接的本地描述。 这是代码:

发件人

function gotStream(stream) {
  console.log('Received local stream');
  // Call the polyfill wrapper to attach the media stream to this element.
  localstream = stream;     
 audio1 = attachMediaStream(audio1, stream);
 pc1.addStream(localstream);
 console.log('Adding Local Stream to peer connection');
 pc1.createOffer(gotDescription1, onCreateSessionDescriptionError);
}

 function gotDescription1(desc) {
   pc1.setLocalDescription(desc);
   console.log('Offer from pc1 \n' + desc);
   console.log('Offer from pc1 \n' + desc.sdp);
     $.ajax({
     type: "POST",
     url: '../../home/saveaddress',
     contentType: "application/json; charset=utf-8",
     data: JSON.stringify({ SDP: desc }),
     dataType: "json",
     success: function (result) {
        if (result) {
           console.log('SDP Saved');
        } 
    });
  }
function iceCallback2(event) {
    if (event.candidate) {
   pc1.addIceCandidate(event.candidate,
   onAddIceCandidateSuccess, onAddIceCandidateError);
   console.log('Remote ICE candidate: \n ' + event.candidate.candidate);
 }
}

在接收端

 var pcConstraints = {
        'optional': []
    };
    pc2 = new RTCPeerConnection(servers, pcConstraints);
    console.log('Created remote peer connection object pc2');
    pc2.onicecandidate = iceCallback1;
    pc2.onaddstream = gotRemoteStream;

$.ajax({
    type: "GET",
    url: '../../home/getsavedaddress',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (result) {
        if (result) {
            gotDescription1(result);
        }
    },
    error: function () {

    }
});
    function gotDescription1(desc) {

    console.log('Offer from pc1 \n' + desc.sdp);
    console.log('Offer from pc1 \n' + pc2);

    pc2.setRemoteDescription(new RTCSessionDescription(desc));
    pc2.createAnswer(gotDescription2, onCreateSessionDescriptionError,
 sdpConstraints); 
 }

使用这个我从 server 获取 SDP , vedio 标签现在有一个来源。但视频没有播放没有显示任何东西。任何线索.. 我也是用asp.net做网站的,这个项目需要用nodejs吗?

谢谢

【问题讨论】:

  • 为什么不在应答器中设置接收音频的提议?

标签: sockets webrtc


【解决方案1】:

您的问题缺乏信息,但我会就此发表意见。

您支持 Trickle ICE 吗?看来您发送 SDP 的速度可能太快了!

当你做一个

pc1.setLocalDescription(desc);

根据您在此处代码中配置的 TURN 和 STUN 服务器(servers 参数)开始收集 ICE 候选者:

pc2 = new RTCPeerConnection(servers, pcConstraints);

也就是说,它们尚未包含在您的 SDP 中。在 localDescription 对象中设置媒体端口之前可能需要几毫秒。您的第一个错误是您从 gotDescription1 而不是 post setLocalDescription SDP 发送“desc”对象。该 SDP 还没有合适的媒体端口。

在您的代码中,您无需等待即可立即发送 SDP。我的猜测是 SDP 尚未完成,您不支持 Trickle。因此,即使信号看起来不错,您也不会看到任何媒体流动。

【讨论】:

    猜你喜欢
    • 2020-10-10
    • 1970-01-01
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多