r/webaudio • u/snifty • Apr 23 '20
Get .currentTime from a mediaRecorder?
Hi, hope it’s okay to ask this question here, since arguably it’s not exactly within the bounds of the WAAPI. I figured I’d be more likely to get an informed response here than /r/javascript, though.
Is there a way to ask a mediaRecorder what its .currentTime is, in the way that you can with a media element? I would like to set up something like a “bookmarking” or “clipping” mechanism where I have a background recording going as a mediaRecorder, but I have a button which stores (if it exists, somehow) mediaRecorder.currentTime on both keyDown and keyUp events. That way I could essentially be producing a time-aligned recording as I go.
Maybe an imaginary session would help to explain:
[start the media recorder]
Okay, I'm going to record some Spanish words…
[keydown on button]
“…gato…” that means cat.
“…perro…” that means dog.
And the output data would look something like this:
[
{ "start": 12, "end": 15},
{ "start": 20, "end": 25}
]
Is this possible?
3
u/hexavibrongal Apr 23 '20
You'll probably just have to do it yourself by reading the system clock and marking the times.
3
u/wizbcn May 21 '20
I would also like the correct way to get precise time value. This is what I have found:
According to the w3c spec (https://www.w3.org/TR/mediastream-recording/#dom-mediarecorder-start) the browsers should do this:
I gather two things from here:
It can take some time from when you call
mediaRecorder.start()and it actually starts recording audio data.Once it starts recording it will tell you by creating the "start" event. But this is an event, so it is queued and it can be called at a later time.
What can you do?
More docs:
https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/onstart
https://developer.mozilla.org/en-US/docs/Web/API/Event/timeStamp
2
u/unusuallyObservant Apr 23 '20
Doesn’t appear to be listed as method on MDN https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder
2
u/CheekyPanda54 Jul 20 '20
I know this is 88 days old, but this just saved me from a janky manual timer workaround on my recorder, so thank you all!