I am working on a chrome extension that let user record their current tab video + the current system audio for example playing a music on the tab. I read the docs on the web about preserve audio on tab capture api, but its not clear on how to implement it :-
const output = new AudioContext();
const source = output.createMediaStreamSource(stream);
source.connect(output.destination);
const stream = await new Promise<MediaStream | null>((resolve, reject) => {
chrome.tabCapture.capture({
video: true,
audio: true,
videoConstraints: {
mandatory: {
minFrameRate: 60,
maxFrameRate: 60,
minWidth: 1920,
minHeight: 1080,
maxWidth: 1920,
maxHeight: 1080,
}
}
}, (stream: MediaStream | null) => {
if (chrome.runtime.lastError) {
return reject(new Error(chrome.runtime.lastError.message));
}
resolve(stream);
});
});
In the above code, when I set the audio to be true and try to record the screen, the final output doesn’t contain any audio and when recording the system also won’t play the audio
Any help would be greatly appreciated 🙂