4

I have been going over the WebRTC docs and I see two WebRTC methods where I am not sure I understand what the difference is: reattachMediaStream and attachMediaSource.

attachMediaSource This I get, you use it to attach a MediaStream to something like a video element.

HTML:

<video id="videoPlayer">

JS:

attachMediaSource(videoPlayer, mediaSource);

But when is reattachMediaStream used?

Looking at the adapter.js code the WebRTC group provides, doesn't help much.

For Gecko it has:

  reattachMediaStream = function(to, from) {
    console.log("Reattaching media stream");
    to.mozSrcObject = from.mozSrcObject;
    to.play();
  };

For webkit it has:

  reattachMediaStream = function(to, from) {
    to.src = from.src;
  }

Looking at all the various examples out there also hasn't helped. I don't see anything using reattachMediaStream.

Is it attaching the video from one video element to another?

4

1 回答 1

3

您是对的:该reattachMediaStream方法允许您将相同的媒体流附加到多个视频元素。
有关用法示例,请查看此页面,第 350 行:

function onRemoteStreamAdded(event) {
    console.log("Remote stream added."); 
    reattachMediaStream(miniVideo, localVideo);
    attachMediaStream(remoteVideo, event.stream);
    remoteStream = event.stream;
    waitForRemoteVideo();  
}

在此示例中,该方法用于在页面右下角的小窗口中显示本地视频的预览。

于 2013-09-29T08:11:57.350 回答