我正在为iPhone上的视频应用程序创建应用,但我不知道如何在iPhone上捕获视频;我想将它们存储在SQLite数据库中,但我有一个问题:我能直接将视频保存在SQLite数据库中吗?是否可能,还是我必须存储视频路径?如果我必须在SQLite数据库中保存路径,那么我该怎么做呢?请在这个问题上帮帮我。
我正在为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.
}
}
希望这能帮到你。