9

我想知道接收到的流 onaddstream 回调中的轨道存在。视频通话效果很好,但我想做。仅音频调用,所以我只是传入audio:true,video:false了 getUserMedia 约束,现在当我收到流时,我无法确定流中的轨道存在。

如何知道流中的曲目存在?

4

1 回答 1

7

To Know presence of Audio and Video use getAudioTracks and getVideoTracks.

function checkStream(stream){

   var hasMedia={hasVideo:false,hasAudio:false};

   if(stream.getAudioTracks().length)// checking audio presence
      hasMedia.hasAudio=true;

   if(stream.getVideoTracks().length)// checking video presence
      hasMedia.hasVideo=true;

    return hasMedia; 
}

To stop passing Video in stream change offer and answer constrinats.

constraints = {
            optional: [],
            mandatory: {
                OfferToReceiveAudio: true,
                OfferToReceiveVideo: false
            }
        };
于 2013-05-28T09:43:31.793 回答