In this episode, we're diving into how to enable audio capture while using the Media Recorder API in the browser. We kick things off by talking about how the browser's Media Recorder API can only capture one stream at a time, so to grab audio and video simultaneously, we need to handle the audio stream separately and then combine them later.
We walk through adding a simple toggle (a checkbox) to let users decide if they want to capture audio at all. This might look like a straightforward UI update, but it's really helpful for users who might just want to record their screen without sound. The checkbox connects to a Vue ref
, and we keep it enabled by default, but users can turn it off if they prefer.
The coding part involves using getUserMedia
to grab the audio, setting options like echo cancellation, noise suppression, and auto gain control for cleaner sound. We set up our state to hold the audio stream separately from the video, and wire things up so that audio capture only happens if the toggle is enabled.
We quickly test this in the browser to see how things behave (with browser prompts and everything). When both streams are being captured, you won’t "see" or "hear" audio directly, but it’s there and ready to be merged when recording starts. By the end, you’ll know exactly how to wire up conditional audio capture for your recording app, and how to manage multiple streams in preparation for combining them into a single recording. Super handy if you want more control over your media recorder features!