In this episode, we tackle the core of actually recording our video (and audio!) in the browser. We kick things off by building a simple UI—just a container under our video preview with a nice, centered 'Start Recording' button. Once that's in place and looking good, we wire it up so a click gets the recording process rolling.
The main challenge here is that we want to record both video (screen or webcam) and audio at the same time. Since browsers give us these as separate streams, we combine them into a single MediaStream object—thanks MediaStream API! That way, both video and audio get captured together seamlessly.
We then use the MediaRecorder API to actually start gathering data, capturing it in small chunks (about every 300ms). These chunks go into an array and, later on, we’ll piece them together into a single blob for playback or upload. As we go, we also add the flexibility to stop the recording, stop all tracks, and clear up our state.
We update the UI so that when recording starts, the 'Start Recording' button switches to a prominent red 'Stop Recording' one. Finally, we make sure to handle edge cases—like missing audio permission or empty data chunks—so nothing breaks.
By the end of this video, we have a complete recording flow, with all our video and audio data neatly chunked and ready for the next steps, like preview or upload. We’re ready to build on this and make it even better in future episodes!