Created
August 7, 2020 02:40
-
-
Save VadimBrodsky/f4ad0b48a79fc02307d3271e9d60460f to your computer and use it in GitHub Desktop.
RecordRTC React Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useRef, useEffect } from 'react'; | |
import './App.css'; | |
import RecordRTC, { invokeSaveAsDialog } from 'recordrtc'; | |
function App() { | |
const [stream, setStream] = useState(null); | |
const [blob, setBlob] = useState(null); | |
const refVideo = useRef(null); | |
const recorderRef = useRef(null); | |
const handleRecording = async () => { | |
// const cameraStream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true }); | |
const mediaStream = await navigator.mediaDevices.getDisplayMedia({ | |
video: { | |
width: 1920, | |
height: 1080, | |
frameRate: 30, | |
}, | |
audio: false, | |
}); | |
setStream(mediaStream); | |
recorderRef.current = new RecordRTC(mediaStream, { type: 'video' }); | |
recorderRef.current.startRecording(); | |
}; | |
const handleStop = () => { | |
recorderRef.current.stopRecording(() => { | |
setBlob(recorderRef.current.getBlob()); | |
}); | |
}; | |
const handleSave = () => { | |
invokeSaveAsDialog(blob); | |
}; | |
useEffect(() => { | |
if (!refVideo.current) { | |
return; | |
} | |
// refVideo.current.srcObject = stream; | |
}, [stream, refVideo]); | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<button onClick={handleRecording}>start</button> | |
<button onClick={handleStop}>stop</button> | |
<button onClick={handleSave}>save</button> | |
{blob && ( | |
<video | |
src={URL.createObjectURL(blob)} | |
controls | |
autoPlay | |
ref={refVideo} | |
style={{ width: '700px', margin: '1em' }} | |
/> | |
)} | |
</header> | |
</div> | |
); | |
} | |
export default App; |
I'm not able to get camera preview while recording, is there any way to get like this in react ?
Hi How to convert it into file and send it to backend please add that file in video format
Hi, Thanks for the script.
Recording from local microphone is clear to me.
Question: How do I record the remote audio (incoming audio) using RecordRTC?
Thank you.
hi, any React Native solution?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you are very great,thankyou~!!!