Tom
Tom

Reputation: 794

How to deal with the media stream I get from "chrome.tabCapture"?

I am now testing the new chrome API "chrome.tabCapture". It returns the local media stream, but what can I do with the media stream? Can it be turned into one kind of video type or directly be played.

var obj = {
    audio: false,
    video: true

};
chrome.tabCapture.capture(obj, function (stream) {
// what to do with the stream?  
});

I have tried var url = window.URL.createObjectURL(stream); video.src = url; but it doesn't work.

Upvotes: 2

Views: 4280

Answers (3)

Davit Mkrtchyan
Davit Mkrtchyan

Reputation: 469

Very basic usage is this. In startStream function you can add listeners, and manipulate stream.

var obj = {
    audio: false,
    video: true
};

 function startStream(stream){ 
     var streamObject = new MediaRecorder(stream);    

     streamObject.ondataavailable = function(blob){
       video.src = URL.createObjectURL(blob.data);
     }
}

chrome.tabCapture.capture(obj, startStream );

Hope this helps.

Upvotes: 0

Abbas
Abbas

Reputation: 146

Download and install the tabcapture example extension from this link

https://developer.chrome.com/extensions/samples#search:tabcapture

Check eventPage.js and receiver.js.

Also Check

https://www.w3.org/TR/mediastream-recording/

https://developers.google.com/web/updates/2016/01/mediarecorder

You can get some idea from that.

Upvotes: 2

JasonEleventeen
JasonEleventeen

Reputation: 343

It looks like you should then be able to use the MediaRecorder to record the LocalMediaStream to blobs, but I don't think chrome has MediaRecorder yet so all you can do is put the stream back to a video tag or a webRTC connection

http://dart-gde.github.io/chrome_gen.dart/ext/chrome.src.common_exp/LocalMediaStream.html https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder_API

This git tree might help as it has cross browser code https://github.com/streamproc/MediaStreamRecorder

var video = document.createElement('video');
video.src = URL.createObjectURL(mediaStream);
video.play();

Upvotes: 1

Related Questions