In this episode, we take the video chunks we've been recording from the browser and stitch them together into a single video that we can actually preview.
We start off by taking the array of blobs (those chunks the browser gives us each time data becomes available during recording) and creating a new Blob from them. This gives us our full video in a format the browser can play back. We go over the differences in video formats across browsers (like how Safari might use mp4, while Chrome records in webm), but for the purposes of our preview, we just use whatever we get.
After that, we update our app's state to store the blob, clean up the chunks array, and compute a blob URL. This blob URL is what we can hand directly to a video element's source so we can see a preview right inside the browser.
We rework the template so that once a video has been recorded, it shows the preview at the top, hiding the initial recording controls. We discuss why we use v-show
instead of v-if
—so our refs stay available and everything reacts nicely. Then, we hook up the blob URL to our preview video element, add controls for scrubbing and playback, and make sure the source is set correctly.
To wrap up, we fix a couple of small bugs around how we're handling the video source, do a couple of test runs, and confirm that the preview works: you can record yourself, stop recording, and immediately watch your recording back in the page. Next up, we'll move on to building the form so we can actually upload our video to the backend!