

Then a new Promise which resolves when the preview video starts to play is created and returned.

Then, in line 8, we arrange for preview.captureStream() to call preview.mozCaptureStream() so that our code will work on Firefox, on which the HTMLMediaElement.captureStream() method is prefixed. The "Download" button's link is then set to refer to the stream as well. Since the element is muted, the audio won't play. When the Promise returned by getUserMedia() is resolved, the preview element's srcObject property is set to be the input stream, which causes the video being captured by the user's camera to be displayed in the preview box. MediaDevices.getUserMedia is called to request a new MediaStream that has both video and audio tracks. When a click event occurs, here's what happens: Lines 2-4 Function startRecording ( stream, lengthInMS ), false )
