Page 1 of 1

Not show the time/seconds until ‘record’ starts on html5 player

Posted: Thu Jun 24, 2021 1:56 pm
by Chrisj
This code allows the page vistor to click a ‘display’ button to show the camera view on the page, but not start the video recording (they can select a seperate ‘record’ button to start recording). However, the timer/seconds start upon selecting ‘display’ the camera view. I’d like help with having the time/seconds not start until ‘record’ button is clicked. Any help/guidance is appreciated. Here’s the code:

Code: Select all

let blobs = [];
let stream, mediaRecorder, blob;

let video = document.getElementById("video");
var displaying = false;
var recording = false;
async function display() {
  stream = await navigator.mediaDevices.getUserMedia({
    audio: true,
    video: true,
  video.srcObject = stream;
  displaying = true;
function startRecording() {
    mediaRecorder = new MediaRecorder(stream);
    mediaRecorder.ondataavailable = (event) => {
    // Let's append blobs for now, we could also upload them to the network.
      if ( {
    mediaRecorder.onstop = doPreview;
    // Let's receive 1 second blobs
    recording = true;

function endRecording() {
    // Let's stop capture and recording
    stream.getTracks().forEach((track) => track.stop());
    recording = false;

function doPreview() {
  if (!blobs.length) {
  // Let's concatenate blobs to preview the recorded content
  blob = new Blob(blobs, { type: mediaRecorder.mimeType });
  video.srcObject = null;
  video.src = URL.createObjectURL(

Re: Not show the time/seconds until ‘record’ starts on html5 player

Posted: Mon Jun 28, 2021 8:20 am
by Chrisj
The video player is simply the video element: ... ment/video
Here's the corresponding html:

Code: Select all

<video id="video" autoplay controls muted playsInline></video>

<button id="display" onclick="display()">Camera View</button>
<button id="start" onclick="startRecording()">Start Recording</button>
<button id="stop" onclick="endRecording()">Stop Recording</button>
It was suggested that I need to remove the video controls from the video first and then add them back when the recording starts. But I don't know how to do that.

any help is appreciated.