gpt4 book ai didi

iphone - 如何在 iPhone 中捕捉视频

转载 作者:太空狗 更新时间:2023-10-30 03:46:55 28 4
gpt4 key购买 nike

我正在为 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];
}

然后你应该实现以下委托(delegate)方法来保存捕获的视频。将视频路径存储在 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.
}
}

希望这对您有所帮助。

关于iphone - 如何在 iPhone 中捕捉视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6276351/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com