【问题标题】:Record a video automatically for 15 secs and save it to directory自动录制视频 15 秒并保存到目录
【发布时间】:2016-09-21 15:05:38
【问题描述】:

我想在我按下按钮时自动从我的 iphone 设备录制视频,录制 15 秒后视频应该停止,我想将视频保存到目录中。

我曾尝试使用 imagepicker,但为此我们需要手动按下开始按钮来开始视频录制。我希望当用户按下按钮时相机应该开始录制视频。

谢谢。

【问题讨论】:

标签: iphone ios video


【解决方案1】:

您可以通过使用 UIImagePickerController 本身来做到这一点。您提到您需要手动按下开始按钮,但这是不对的。

参考Apple's Documentation

有实例方法可用于通过代码捕获视频。startVideoCapturestopVideoCapture

点击按钮实例化 imagePicker 对象.. 然后调用以下方法。

[yourImagePickerObject startVideoCapture];

之后您可以调用计时器或在延迟 15 秒后执行选择器并可以调用

[yourImagePickerObject stopVideoCapture];

此方法将调用您的图像选择器的委托方法– imagePickerController:didFinishPickingMediaWithInfo:

您可以在这里处理媒体并将其写入文档目录。

更新

单击按钮时,您将显示图像选择器并调用startVideoCapture 方法,即使这不起作用,也只能尝试在 presentModalView 行之后关注按钮的事件:

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 的值。 希望这会有所帮助:)

【讨论】:

  • 我在这行之前试过这个方法 [self presentModalViewController:videoRecorder animated:YES];仍然没有自动录制
  • 是的,但是在捕获视频后,我可以选择使用并重新拍摄,我不想要并且只想保存视频
  • 尝试设置videoRecorder.showsCameraControls=NO; 不确定是否有效,但您可以尝试。
  • 没有帮助。它只是没有显示控件,但视频没有停止
  • 我在按钮和其他 stopVideoCapture 上使用 startVideoCapture ,但我无法保存录制视频,因为 didfinshpickingmediainfo 方法不起作用..任何人都可以帮助我吗??
【解决方案2】:

可能将VideoMaximumuration 设置为 15 秒会解决您的问题

[yourImagePickerObject setVideoMaximumDuration:15];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 2016-03-25
    相关资源
    最近更新 更多