✨ isRecording() prop for cameraRef
What feature or enhancement are you suggesting?
Right now, you can use:
- cameraRef.current?.startRecording()
- cameraRef.current?.stopRecording()
- cameraRef.current?.pauseRecording()
- cameraRef.current?.resumeRecording()
If you call stopRecording() twice, you get a console.warn that you called it twice.
Would be awesome to be able to control this logic within code like so:
if(cameraRef.current?.isRecording()) { // could also be cameraRef.current?.isRecordingAsync() possibly
cameraRef.current?.stopRecording() // prevent the warning and also get the status of the camera.
}
What Platforms whould this feature/enhancement affect?
iOS, Android
Alternatives/Workarounds
Right now, you just set a separate state variable when you call:
cameraRef.current.startRecording({
flash,
fileType: "mp4",
onRecordingError: (error) => {
console.error("Recording failed!", error)
},
onRecordingFinished: (video) => {
console.log(`Recording successfully finished! ${video.path}`)
onMediaCaptured(video, "video")
setCameraRecording(false) // track current state of camera in separate variable
},
})
setCameraRecording(true) // track current state of camera in separate variable
Additional information
- [X] I agree to follow this project's Code of Conduct
- [X] I searched for similar feature requests in this repository and found none.
Good feature request, but I think the answer would be the API I mentioned in this comment: https://github.com/mrousavy/react-native-vision-camera/issues/1319#issuecomment-1741728183
So something like
const recorder = await camera.current.prepareRecorder()
console.log(recorder.state) // <-- 'idle'
await recorder.start()
console.log(recorder.state) // <-- 'recording'
await recorder.pause()
console.log(recorder.state) // <-- 'recording-paused'
await recorder.stop()
console.log(recorder.state) // <-- 'finished' (or idle again?)
Also, in your code:
setCameraRecording(true) // track current state of camera in separate variable
If you don't display this to the user, it would be better to use a useRef for this (state only immutably updates callbacks)
@mrousavy that would work great too! Thanks again
Yea but I'm not gonna work on this for a while, maybe some point in the future. If you need this we can of course build this feature for you through my consultancy company, otherwise I'll maybe take a look at this when VisionCamera is a TurboModule :)