如何在iPhone中捕捉视频 [英] how to capture video in iPhone
问题描述
我正在iPhone中创建视频应用程序的应用程序,但我不知道如何在iPhone中捕获视频;我想将它们存储在SQLite数据库中,但我有一个问题:我可以在SQLite数据库中保存直接视频吗?是可能的,还是我必须存储视频的路径?如果我必须在SQLite数据库中保存路径,那么我该怎么做呢?请帮忙解决这个问题。
I am creating application for video app in iPhone, but I don't know how to capture a video in iPhone; and I want to store them in SQLite database, but I have one problem: can I save direct video in SQLite database? Is is possible, or I have to store path of video? If I have to save path in SQLite database, then how can I do this? Please help in this problem.
推荐答案
只有iPhone 3GS及以上才支持视频录制。所以你应该首先检查是否支持录制。然后使用以下代码启动具有为属性设置的所需值的相机。
您将使用MobileCoreServices / MobileCoreServices.h来运行此代码。
Only iPhone 3GS and above support video recording.so you should first check if recording is supported and then start camera with desired values set for properties,using following code.
You will have "MobileCoreServices/MobileCoreServices.h" to run this code.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *videoRecorder = [[UIImagePickerController alloc]init];
NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:videoRecorder.sourceType];
NSLog(@"Available types for source as camera = %@", sourceTypes);
if (![sourceTypes containsObject:(NSString*)kUTTypeMovie] ) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:@"Device Not Supported for video Recording." delegate:self
cancelButtonTitle:@"Yes"
otherButtonTitles:@"No",nil];
[alert show];
[alert release];
return;
}
videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
videoRecorder.mediaTypes = [NSArray arrayWithObject:(NSString*)kUTTypeMovie];
videoRecorder.videoQuality = UIImagePickerControllerQualityTypeLow;
videoRecorder.videoMaximumDuration = 120;
videoRecorder.delegate = self;
self.recorder_ = videoRecorder;
[videoRecorder release];
[self presentModalViewController:self.recorder_ animated:YES];
}
然后你应该实现以下委托方法来保存捕获的视频。观看视频路径在SQL / coredata中是理想的,而不是将整个视频文件存储在其中。
Then you should implement following delegate method to save the captured video.Storing video path in SQL/coredata would be ideal instead of storing entire video file in it.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
if ([type isEqualToString:(NSString *)kUTTypeVideo] ||
[type isEqualToString:(NSString *)kUTTypeMovie]) { // movie != video
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSData *videoData = [NSData dataWithContentsOfURL:videoUrl];
NSString *videoStoragePath;//Set your video storage path to this variable
[videoData writeToFile:videoStoragePath atomically:YES];
//You can store the path of the saved video file in sqlite/coredata here.
}
}
希望这有帮助。
这篇关于如何在iPhone中捕捉视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!