Roc*_*cky 5 iphone objective-c
我正在iPhone中创建视频应用程序的应用程序,但我不知道如何在iPhone中捕获视频; 我想将它们存储在SQLite数据库中,但我有一个问题:我可以在SQLite数据库中保存直接视频吗?是可能的,还是我必须存储视频的路径?如果我必须在SQLite数据库中保存路径,那么我该怎么做呢?请帮助解决这个问题.
ama*_*avi 16
只有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];
}
Run Code Online (Sandbox Code Playgroud)
然后你应该实现以下委托方法来保存捕获的视频.在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.
}
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
7836 次 |
| 最近记录: |