Skip to content

Commit

Permalink
Add microphone input to tabcapture sample for crbug/1400269
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverdunk committed Nov 13, 2023
1 parent 9aaa5ca commit 9ee3bb9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion functional-samples/sample.tabcapture-recorder/offscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,22 @@ async function startRecording(streamId) {
source.connect(output.destination);

// Start recording.
recorder = new MediaRecorder(media, { mimeType: 'video/webm' });
const microphone = await navigator.mediaDevices.getUserMedia({
audio: { echoCancellation: false }
});

const mixedContext = new AudioContext();
const mixedDest = mixedContext.createMediaStreamDestination();

mixedContext.createMediaStreamSource(microphone).connect(mixedDest);
mixedContext.createMediaStreamSource(media).connect(mixedDest);

const combinedStream = new MediaStream([
media.getVideoTracks()[0],
mixedDest.stream.getTracks()[0]
]);

recorder = new MediaRecorder(combinedStream, { mimeType: 'video/webm' });
recorder.ondataavailable = (event) => data.push(event.data);
recorder.onstop = () => {
const blob = new Blob(data, { type: 'video/webm' });
Expand Down

1 comment on commit 9ee3bb9

@PaulAsaf2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great! The solution helped to connect the microphone to the audio from the tab!

Please sign in to comment.