iPhone: 5 seconds video capture

2019-07-19 17:45发布

问题:

I would like to write code so that when the user presses a button, the camera is launched and records 5 seconds of video. In other words I want to have video capture but with a time limit.

Is there something inside the UIImagePickerController or other parts of the framework that would allow doing this? Thank you.

回答1:

There is nothing that allows you to directly do this. But you can very easily use UIImagePickerController's startVideoCapture to begin the capture and then call stopVideoCapture 5 seconds later, for example with [picker performSelector:@selector(stopVideoCapture) withObject:nil afterDelay:5].

Or you can do basically the same thing with AVFoundation, in particular AVCaptureMovieFileOutput's startRecordingToOutputFileURL:recordingDelegate: and stopRecording methods.