I have a MediaStream
with 1 audio track and 2 video tracks. This stream is created by combining the audio and video track from navigator.mediaDevices.getUserMedia
with the video track from navigator.mediaDevices.getDisplayMedia
.
var camStream = await navigator.mediaDevices.getUserMedia({audio: true, video: true, width: "1280"});
var screenStream = await navigator.mediaDevices.getDisplayMedia({video: true, width: "1280"});
var screenTrack = screenStream.getVideoTracks()[0];
camStream.addTrack(screenTrack);
At this point, camStream
has 1 audio track and 2 video tracks.
I have an HTML element <video id="local-video"></video>
which I use to play the stream by setting the srcObject attribute:
document.getElementById("local-video").srcObject = camStream;
The problem is that I can't choose which track is being played. The camStream video track always plays over the the screenStream video track. Is there a way where I can keep both video tracks in the stream, but choose which one is currently playing in the video element?
So far the only thing that's worked is to remove one of the video tracks from the stream so that the other can play, but I'd like to keep both video tracks in the stream so that I can switch b/w them.