Skip to content

Commit

Permalink
More examples of timeslice being inexact, 1st mention of oversized ch… (
Browse files Browse the repository at this point in the history
#36187)

* More examples of timeslice being inexact, 1st mention of oversized chunks

* Update files/en-us/web/api/mediarecorder/dataavailable_event/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Update files/en-us/web/api/mediarecorder/dataavailable_event/index.md

Co-authored-by: Joshua Chen <[email protected]>

---------

Co-authored-by: Joshua Chen <[email protected]>
  • Loading branch information
octavn and Josh-Cena authored Oct 16, 2024
1 parent ce9feb3 commit e4678a8
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object that contains the data. This occurs in four situations:
- If a `timeslice` property was passed into the
{{domxref("MediaRecorder.start()")}} method that started media capture, a
`dataavailable` event is fired every `timeslice` milliseconds.
That means that each blob will have a specific time duration (except the last blob,
That means that normally, each blob will have a specific time duration (except the last blob,
which might be shorter, since it would be whatever is left over since the last event).
So if the method call looked like this — `recorder.start(1000);` — the
`dataavailable` event would fire after each second of media capture, and
Expand All @@ -34,7 +34,9 @@ object that contains the data. This occurs in four situations:
produce multiple same-length blobs plus other shorter blobs as well.

> [!NOTE]
> Like other time values in web APIs, `timeslice` is not exact and the real intervals may be slightly delayed due to other pending tasks. Therefore, don't rely on `timeslice` and the number of chunks received to calculate the time elapsed, because errors may accumulate. Instead, keep a separate timer using {{domxref("Event.timeStamp")}} or similar, that records the total time elapsed since starting.
> Like other time values in web APIs, `timeslice` is not exact and the real intervals may be delayed due to other pending tasks, browser features (pausing the camera and microphone in Safari), browser-specific behaviors (locking the screen while recording on Chrome on Android pauses the `dataavailable` event), or other browser bugs. Such scenarios can also lead to significantly larger chunks.
>
> Therefore, don't rely on `timeslice` and the number of chunks received to calculate the time elapsed, because errors may accumulate. Instead, keep a separate timer using {{domxref("Event.timeStamp")}} or similar, that records the total time elapsed since starting.
The {{domxref("Blob")}} containing the media data is available in the `dataavailable` event's `data` property.

Expand Down Expand Up @@ -90,3 +92,4 @@ mediaRecorder.ondataavailable = (e) => {
getUserMedia + Web Audio API visualization demo, by [Chris Mills](https://github.com/chrisdavidmills) ([source on GitHub](https://github.com/mdn/dom-examples/tree/main/media/web-dictaphone).)
- [simpl.info MediaStream Recording demo](https://simpl.info/mediarecorder/), by [Sam Dutton](https://github.com/samdutton).
- {{domxref("Navigator.getUserMedia()")}}
- [Dealing with huge MediaRecorder chunks](https://blog.addpipe.com/dealing-with-huge-mediarecorder-slices/) on addpipe.com (2024)

0 comments on commit e4678a8

Please sign in to comment.