Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make and add a MediaStreamTrack to a media stream

I am wondering how to make and add a MediaStreamTrack to a MediaStream. I cant find a way to add or make one, and so I’m stuck. Please help. Thanks!

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Step 1: Generate the tracks.


const userMedia = await navigator.mediaDevices.getUserMedia({audio : true, video : true});

const videoTrack = userMedia.getVideoTracks()[0];
const audioTrack = userMedia.getAudioTracks()[0];

Step 2: Create a MediaStream and add tracks to them.


const stream = new MediaStream();
stream.addTrack(videoTrack);
stream.addTrack(audioTrack);

Now you can use that MediaStream as whatever you want.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading