Heads up! We're sunsetting this forum to streamline our community space.

join us on Discord for support, updates, and all things Snap AR! See you there!
Sign up for our live Camera Kit office hour on July 17 @ 9:30am (PT) / 4:30pm (GMT)

[Camera-kit for Web] Recording mediastream

Tony
Tony Posts: 5
edited June 2023 in General #1

Hi guys,

I am trying to make a video recording function for camera-kit web. But I have a problem to get mediastream data. Actually, I couldn't get any data at all. I followed the tutorial posted in camera-kit docs. Code is as below.

  1. open capturestream
  2. initialize mediarecorder with capturestream
  3. check data


const stream = session.output.capture.captureStream();
const mediaRecorder = new MediaRecorder(stream, {mimeType: localMimeType});
let localChunks = [];
mediaRecorder.ondataavailable = (e) => {
if (typeof e.data === "undefined") return;
if (e.data.size === 0) return;
localChunks.push(e.data);
};

Comments

  • Michael Mase
    Michael Mase Posts: 66 🔥🔥
    edited June 2023 #2

    Hi @Tony! This is a bit outside of Camera Kit's purview but I'm happy to provide a little guidance based on what I see in your sample code.

    In order for a MediaRecorder instance to begin recording and processing data, you need to call start() on it. Keep in mind, the start method has an optional timeslice parameter (which is the number of milliseconds to record into each Blob). If you don't provide a value for this parameter, the dataavailable event will only be fired after you call stop() on the MediaRecorder instance (which will place all of the recorded data in a single Blob).

    I hope this helps!

Categories