react-media-recorder
react-media-recorder copied to clipboard
With hook mode, you cannot get previewStream without calling startRecording.How to solve it?
With hook(useReactMediaRecorder) mode, you cannot get previewStream without calling startRecording.How to solve it?
is this fixed?
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]);
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])
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
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?