[英]how to capture video in iPhone
我正在为 iPhone 中的视频应用程序创建应用程序,但我不知道如何在 iPhone 中捕获视频; 我想将它们存储在 SQLite 数据库中,但我有一个问题:我可以将直接视频保存在 SQLite 数据库中吗? 是可能的,还是我必须存储视频路径? 如果我必须在 SQLite 数据库中保存路径,那么我该怎么做? 请帮助解决这个问题。
只有 iPhone 3GS 及更高版本支持视频录制。所以您应该首先检查是否支持录制,然后使用以下代码为属性设置所需的值启动相机。
您将拥有“MobileCoreServices/MobileCoreServices.h”来运行此代码。
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 中是理想的,而不是将整个视频文件存储在其中。
-(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.
}
}
希望这可以帮助。
您可以将 sqlite 中的视频数据作为原始数据存储,但我强烈建议您不要这样做。 表现会很糟糕。 最好将视频保存到文档目录,然后保存到数据库中的路径。
如果您正在使用 sqlite,那么您应该查看 CoreData,它使管理持久性变得更加容易......下载我的核心数据教程的源代码,因为它包含一个很好的存储服务包装器...... 教程在这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.