recordAsync is not a closed loop with stopRecording

Not sure if this is a bug, but this doesn’t work:

        setTimeout(() =>     cameraRef.current.stopRecording(), 100)
        const {uri} = await cameraRef.current.recordAsync();
       console.log("should be cancelled!")

The console will not log. If you change the timeout to 1000 it will work.

Also, if you replace with pausePreview() it will still not stop the video (just pause the preview).

The problem here is that there is no way for me to tell if the recording can actually be canceled. recordAsync does not guarantee that stopRecording() will actually function.

Managed SDK 39.

stopRecording is probably firing before recordAsync has time to finish setting up

try setting the timeout after recordAsync

You can’t do that because recordAsync blocks the thread until stopRecording gets called.

There is no way to programmatically know when the recordAsync can be killed…so now you have to create a retry function that runs every X ms to check…

The way it should work…recordAsync should return as soon as the camera actually starts and then you should be able to cancel it after that. That way you could set a ref.current flag to say it’s cancellable…

Then when you stopRecording…that should return the actual data…

maybe something like…

const recording = cameraRef.current.recordAsync()
setTimeout(() => cameraRef.current.stopRecording(), 100)
const { uri } = await recording

i seem to recall something like cameraRef.current.isRecording used to be a thing, but only on iOS

maybe recordAsync could mark that a recording has been initialized before returning the promise but before the first frame is recorded,
and stopRecording could fire any time after the promise is returned and abort the upcoming recording
but what would it return? a uri pointing to a video of 0ms duration?

maybe recordAsync could mark that a recording has been initialized before returning the promise but before the first frame is recorded,

Well…then it would have to be a promise :wink:

What you showed is essentially the same thing I had…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.