如何使用Objective-C在iPhone中录制视频? [英] How to record video in iPhone using Objective-C?

查看:71
本文介绍了如何使用Objective-C在iPhone中录制视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个地图应用程序,其中有一个名为video的按钮.如果用户单击视频"按钮,则可以在自己喜欢的任何位置录制视频,并同时播放视频.

I have a map application in which there is a button named video. If a user clicks on the video button he can record video at any location he like and simultaneously play the video.

我该怎么做?我的代码如下:

How can I do this? My code is as follows:

-(IBAction)video:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType]; if (![sourceTypes containsObject:(NSString *)kUTTypeMovie ]){ NSLog(@"device not supported"); return; } picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeVideo]; picker.videoQuality = UIImagePickerControllerQualityTypeHigh; [self presentModalViewController:picker animated:YES]; } 

推荐答案

来自

从iPhone OS 3.0开始,您可以 录制视频,包括音频 支持的设备.显示 视频录制界面,创建和 推送一个UIImagePickerController对象, 就像显示 静止摄像头界面.

Starting in iPhone OS 3.0, you can record video, with included audio, on supported devices. To display the video recording interface, create and push a UIImagePickerController object, just as for displaying the still-camera interface.

要录制视频,必须首先检查摄像机的信号源类型 (UIImagePickerControllerSourceTypeCamera) 可用,并且电影媒体 类型(kUTTypeMovie)可用于 相机.视媒体而定 您分配给mediaTypes的类型 属性,选择器可以直接 显示静态相机或视频 相机或选择界面 让用户选择.

To record video, you must first check that the camera source type (UIImagePickerControllerSourceTypeCamera) is available and that the movie media type (kUTTypeMovie) is available for the camera. Depending on the media types you assign to the mediaTypes property, the picker can directly display the still camera or the video camera, or a selection interface that lets the user choose.

使用UIImagePickerControllerDelegate 协议,注册为代理 图像选择器.您的委托对象 接收完整的视频记录 通过 imagePickerController:didFinishPickingMediaWithInfo: 方法.

Using the UIImagePickerControllerDelegate protocol, register as a delegate of the image picker. Your delegate object receives a completed video recording by way of the imagePickerController:didFinishPickingMediaWithInfo: method.

在受支持的设备上,您还可以从 用户的照片库.

On supported devices, you can also pick previously-recorded videos from a user’s photo library.

有关使用图像选择器类的更多信息,请参见 UIImagePickerController类别 参考.有关修剪的信息 录制的视频,请参见 UIVideoEditorController类 参考和 UIVideoEditorControllerDelegate 协议参考.

For more information on using the image picker class, see UIImagePickerController Class Reference. For information on trimming recorded videos, see UIVideoEditorController Class Reference and UIVideoEditorControllerDelegate Protocol Reference.

一旦您的视频在UIImagePickerController委托中,您就可以使用标准文件操作将其保存到应用程序的documents目录中.

Once you have the video in your UIImagePickerController delegate you can then save it to your app's documents directory using standard file operations.

这篇关于如何使用Objective-C在iPhone中录制视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆