Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support video recording on iOS #308

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

mario-deaconescu
Copy link

Closes #307

@alexandargyurov
Copy link

On Android, await CameraPreview.stopRecordVideo() returns {videoFilePath: string}
On iOS, await CameraPreview.stopRecordVideo() returns {value: string}

@alexandargyurov
Copy link

On iOS, CameraPreview.stopRecordVideo() seems to stop the camera, while on Android, the camera continues to be switched on.

@mario-deaconescu
Copy link
Author

@alexandargyurov I fixed the mismatch between the return types. In what conditions does your camera turn off? From my testing, simply starting and stopping a recording does not stop the camera. If I display the video recording in the app, it stops, but that's because the video plays some audio, which causes the camera preview to pause until I hide the video again. This behavior does not happen if the video is muted, which leads me to believe that the audio playback is interfering with the audio recording part of the camera. In my opinion, this is a more general issue that does not concern this branch, but I might go look into it once/if this pr gets approved.

Playing audio from within the WebView causes the capture session to stop and (sometimes) not resume automatically, so I added a method to manually resume the capture session without initializing the whole class.
CAPPluginCall.resolve() was being called before the camera actually resumed, so I used a completionHandler to wait for the async code
dantheman2865 added a commit to leapfinder/camera-preview that referenced this pull request Sep 8, 2023
@qliqdev
Copy link

qliqdev commented Nov 28, 2023

is it going to be merged?

@enisit
Copy link

enisit commented Feb 16, 2024

@mario-deaconescu Good job adding this feature! I used this as a patch until this gets merged and discovered small issue with video output. Recorded videos longer than 10 seconds had issues with audio, basically video was playing ok but audio was not playing at all for longer videos. After some research I found that this is the issue https://stackoverflow.com/questions/26768987/avcapturesession-audio-doesnt-work-for-long-videos.
One solution is to change file extension to .mov and second option is to add this line
videoFileOutput?.movieFragmentInterval = CMTime.invalid
before calling videoFileOutput.startRecordingToOutputFileURL
It would be good to include either solution in the PR.

@mario-deaconescu
Copy link
Author

I will look into this issue but I can't make any promises as I've got other projects going on. If you can solve the problem before me, I can let you merge the changes.

The mp4 format recorded in fragments of 10 seconds, so I disabled this option because there was no audio if the recording was longer than 10 seconds
@mario-deaconescu
Copy link
Author

I don't think changing the format of the video would have been a good option since .mov is not generally supported on the web, so I went with the other option. It seems to be fixed for now. If other issues come up, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iOS 16 - stopRecordVideo() returns nothing
4 participants