自动录制视频15秒钟,并将其保存到目录中 [英] Record a video automatically for 15 secs and save it to directory
问题描述
当我按下一个按钮时,我想从iphone设备自动录制视频,录制15秒后,视频应该停止播放,并且我想将视频保存到目录中.
I want to record a video from my iphone device automatically when i press a button and after recording for 15 secs the video should stop and i want to save the video to the directory.
我尝试使用图像选择器,但是为此,我们需要手动按开始按钮以开始视频记录.我希望当用户按下按钮时,摄像头应该开始对视频进行重新编码.
I have tried using imagepicker but for that we need to manually press start button to start video recording. I want that when user presses a button camera should start recoding video.
谢谢.
推荐答案
您可以使用UIImagePickerController
本身来执行此操作.您提到需要手动按开始"按钮,但这不对.
You can do this by using UIImagePickerController
itself. You mentioned that you need to press start button manually but that is not right.
请参阅 Apple的文档
有一些实例方法可用于通过代码捕获视频.startVideoCapture
和stopVideoCapture
.
There are instance method available for capturing video by code.startVideoCapture
and stopVideoCapture
.
在按钮的单击上实例化imagePicker对象.然后调用以下方法.
On button's click instantiate imagePicker object.. and than call following method.
[yourImagePickerObject startVideoCapture];
之后,您可以调用计时器或延迟15 dec后执行选择器,然后可以调用
After that you can either call timer or perform selector after delay of 15 dec and can call
[yourImagePickerObject stopVideoCapture];
此方法将调用图像选择器的委托方法– imagePickerController:didFinishPickingMediaWithInfo:
this method will call your image picker's delegate method – imagePickerController:didFinishPickingMediaWithInfo:
您可以在此处处理媒体并将其写入文档目录.
you can here handle the media and write it to document directory.
更新
在单击按钮时,您正在呈现图像选择器并调用startVideoCapture
方法,即使此方法不起作用,也只是尝试在presentModalView行之后尝试跟踪按钮的事件:
On button's click you are presenting image picker and calling the startVideoCapture
method than even this is not working than just try following on button's event after presentModalView line:
int64_t delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[yourImagePickerobj startVideoCapture];
[objImgPicker performSelector:@selector(stopVideoCapture) withObject:nil afterDelay:15];
});
您可以尝试通过更改delayInSeconds的值来进行尝试. 希望这会有所帮助:)
You can try by changing the delayInSeconds' value. Hope this helps :)
这篇关于自动录制视频15秒钟,并将其保存到目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!