react-media-recorder icon indicating copy to clipboard operation
react-media-recorder copied to clipboard

How can I get previewStream back after clearing blob url?

Open harterc3 opened this issue 4 years ago • 3 comments

I'm building an app where someone can record a video. The first part is just the preview stream which works great when the initially load the page. They tap the record button and it starts recording while still showing the preview. Once they're done recording they hit the stop button and then we no longer show the preview stream and instead give them the video they recorded. If they decide they don't like it and want to try again, we're clearing the blob url and we go back to the first step.

At this point, the previewStream is no longer working. The MediaStream is no longer active and I'm not sure if there is a good way to reactivate it or if I need to totally re-run the useReactMediaRecorder hook.

Any help is appreciated!

export default function RecordPage() {
  const {
    status,
    startRecording,
    stopRecording,
    mediaBlobUrl,
    previewStream,
    clearBlobUrl,
    error
  } = useReactMediaRecorder({
    video: true
  });

  console.log('status', status);
  console.log('error', error);
  console.log('mediaBlobUrl', mediaBlobUrl);
  console.log('previewStream', previewStream);

  if (status === "idle" || (status === "stopped" && !mediaBlobUrl)) {
    return <Ready previewStream={previewStream} startRecording={startRecording} />;
  } else if (status === "recording") {
    return <Recording previewStream={previewStream} stopRecording={stopRecording} />;
  } else if (status === "stopped" && mediaBlobUrl) {
    return <DoneRecording mediaBlobUrl={mediaBlobUrl} clearBlobUrl={clearBlobUrl} />;
  }

  return <p>hello</p>;
}

harterc3 avatar Jul 16 '21 01:07 harterc3

hi @harterc3, landed here searching for solution to same problem. were you able to resolve this?

AWworks avatar May 15 '22 17:05 AWworks

same problem for me

Kukunin avatar Nov 15 '22 05:11 Kukunin

found, that passing stopStreamsOnStop: false option helps

Kukunin avatar Nov 15 '22 06:11 Kukunin