iphone - 如何在 iPhone 中捕捉视频

标签 iphone objective-c

我正在为 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/

相关文章:

ios - UIImages/UIButtons 每次编译程序时表现不同

iphone - 是否可以在 Objective-C 中返回用户属于哪个 iTunes 商店?

ios - KVO 不应该同步工作吗?

objective-c - 以 (@) 符号为前缀的 Objective-C 宏的含义

ios - Realm 是否支持 iOS 中的 LIMIT 查询?

ios - NSString - 如何获取由花括号包围的字符串的一部分

android - Facebook URL 方案不起作用 fb ://publish

ios - 如何在4英寸屏幕的iOS6上设置viewcontroller背景图片

iphone - 创建条件转场

iphone - 在不使用 Segue 的情况下将数据从一个 View Controller 传递到另一个 View Controller