How to get the time of the recording while recording with MediaRecorder

Viewed 1145

I am writing a simple web app that captures the audio coming from the mic with navigator.mediaDevices.getUserMedia and records it with a MediaRecorder object. I am more or less following the example from mdn.

I would like to add a live display of the time of the recording. I am currently relying on performance.now(), which is not very elegant, even more so because I allow the user to pause/resume the MediaRecorder. Is there a way to get the time directly from the MediaRecorder object itself somehow?

1 Answers

It seems that the only solution is to track the recorded time yourself. The MediaRecorder object does not provide such an attribute.

This npm package might be of help.

You should listen on start, resume, stop and pause events.

Related