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

With hook mode, you cannot get previewStream without calling startRecording.How to solve it?

Open jacktao007 opened this issue 3 years ago • 5 comments

With hook(useReactMediaRecorder) mode, you cannot get previewStream without calling startRecording.How to solve it?

jacktao007 avatar Feb 08 '22 03:02 jacktao007

is this fixed?

samuelkarani avatar Mar 01 '22 15:03 samuelkarani

You could programmatically call startRecording since you are using the hook right? Something to the effect of:

  const [isPreviewStarted, setIsPreviewStarted] = useState(false);
  useEffect(() => {
    if (!isPreviewStarted && startRecording) {
      startRecording();
      setIsPreviewStarted(true);
    }
  }, [startRecording, isPreviewStarted]);

evanBurg avatar Jun 02 '22 04:06 evanBurg

You can try waiting for the status prop to be "recording", before doing stuff with the previewStream.

Subscribe to those changes by using useEffect with status in the dependency array:

useEffect(() => {
    if(status === "recording") {
      setVideoScreenContent(previewStream)
    };
  }, [status])

rdauj avatar Jun 12 '22 14:06 rdauj

Can confirm the issue. For me, the right workaround is to pass askPermissionOnMount: true option. Another workaround was to have preview with react-webcam package: https://www.npmjs.com/package/react-webcam, but it's unnecessary dependency I wish to eliminate

Kukunin avatar Nov 15 '22 05:11 Kukunin

The workaround that @Kukunin suggested also has a negative side-effect that your video will flicker when switching between the preview component and the recording component.

Is it possible to have access to previewStream even when not recording?

KayBeSee avatar Oct 25 '23 18:10 KayBeSee