今天写录制视频,我记得一年前写过,但是记不住怎么写了,查下资料,网上各种坑,废了好久都没查到我想要的只是录像,没办法只好找以前旧项目了!写完后想想还是记到博客中,好下次忘了了再查看,也让别让少坑些!
如果想只要录像功能不要拍照功能,需要导入MobileCoreServices.framework 并引入头文件
#import <MobileCoreServices/UTCoreTypes.h>
设置下mediaTypes 如何想只拍照 设置 kUTTypeImage
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie , nil];
imagePicker.sourceType =UIImagePickerControllerSourceTypeCamera;
imagePicker.modalTransitionStyle =UIModalTransitionStyleCoverVertical;
imagePicker.videoMaximumDuration = 30.0f; //设置最长摄像时间
imagePicker.videoQuality = UIImagePickerControllerQualityTypeMedium; //设置摄像图像品质
//imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]; // 照相和录像都有,默认拍照
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie , nil]; //只有录像
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString * mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ( CFStringCompare(( __bridge CFStringRef)mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)
{
NSString *videoPath = (NSString *)[[info objectForKey:UIImagePickerControllerMediaURL]path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(videoPath))
{
// 处理视频
}
}
[picker dismissViewControllerAnimated:YES completion:^{
}];
}