### Install react-media-recorder with npm Source: https://github.com/deltacircuit/react-media-recorder/blob/master/README.md Use npm to install the react-media-recorder package. ```bash npm i react-media-recorder ``` -------------------------------- ### Install react-media-recorder with yarn Source: https://github.com/deltacircuit/react-media-recorder/blob/master/README.md Use yarn to install the react-media-recorder package. ```bash yarn add react-media-recorder ``` -------------------------------- ### Screen Recording with Audio and Custom Video Constraints Source: https://context7.com/deltacircuit/react-media-recorder/llms.txt Enables screen recording, optionally including microphone audio. This example configures specific video constraints like resolution and frame rate, sets the MIME type for the recording, and uses `stopStreamsOnStop` to ensure streams are properly terminated. It also demonstrates how to exclude the current tab from screen sharing options using `selfBrowserSurface`. ```typescript import { useReactMediaRecorder } from "react-media-recorder"; const ScreenRecorder = () => { const { status, startRecording, stopRecording, mediaBlobUrl, error, } = useReactMediaRecorder({ screen: true, audio: true, // Include microphone audio video: { width: 1920, height: 1080, frameRate: 30, }, selfBrowserSurface: "exclude", // Exclude current tab from options preferCurrentTab: false, mediaRecorderOptions: { mimeType: "video/webm;codecs=vp9", videoBitsPerSecond: 2500000, }, stopStreamsOnStop: true, }); return (

Status: {status}

{error &&

Error: {error}

} {mediaBlobUrl && (
); }; ``` -------------------------------- ### Basic Video Recording with useReactMediaRecorder Hook Source: https://context7.com/deltacircuit/react-media-recorder/llms.txt Demonstrates basic video recording using the `useReactMediaRecorder` hook. It includes controls for starting, stopping, pausing, resuming, and clearing recordings, along with displaying the recording status and any errors. A live preview of the recorded video is shown. ```typescript import { useReactMediaRecorder } from "react-media-recorder"; // Basic video recording const VideoRecorder = () => { const { status, startRecording, stopRecording, pauseRecording, resumeRecording, mediaBlobUrl, error, clearBlobUrl, } = useReactMediaRecorder({ video: true }); return (

Status: {status}

{error &&

Error: {error}

} {mediaBlobUrl &&
); }; ``` -------------------------------- ### Handle Recording Errors with Custom Messages Source: https://context7.com/deltacircuit/react-media-recorder/llms.txt Implement robust error handling for media recording. This snippet maps specific error codes to user-friendly messages, guiding users on how to resolve issues like permission denial or device conflicts. ```typescript import { useReactMediaRecorder, RecorderErrors } from "react-media-recorder"; const RobustRecorder = () => { const { status, startRecording, stopRecording, mediaBlobUrl, error } = useReactMediaRecorder({ video: true, audio: true, askPermissionOnMount: true, }); const getErrorMessage = (errorCode: string): string => { const errorMessages: Record = { media_aborted: "Recording was aborted by the system.", permission_denied: "Camera/microphone permission was denied. Please allow access in browser settings.", no_specified_media_found: "No camera or microphone found on this device.", media_in_use: "Camera or microphone is being used by another application.", invalid_media_constraints: "The specified media constraints are not supported.", no_constraints: "No audio or video constraints were specified.", recorder_error: "An error occurred with the media recorder.", }; return errorMessages[errorCode] || "An unknown error occurred."; }; return (

Status: {status}

{error && (
Error: {getErrorMessage(error)}
)} {mediaBlobUrl &&
); }; ``` -------------------------------- ### Video Preview with React Media Recorder Source: https://github.com/deltacircuit/react-media-recorder/blob/master/README.md Demonstrates how to use the `previewStream` prop to display a live video preview to the user. The stream is muted by default to prevent audio feedback. ```tsx const VideoPreview = ({ stream }: { stream: MediaStream | null }) => { const videoRef = useRef(null); useEffect(() => { if (videoRef.current && stream) { videoRef.current.srcObject = stream; } }, [stream]); if (!stream) { return null; } return