视频录制
//拍小视屏
UIImagePickerController *picker =[[UIImagePickerController alloc]init];
picker.sourceType =UIImagePickerControllerSourceTypeCamera;
NSArray *arrMediaTypes=@[(NSString *)kUTTypeMovie];
picker.mediaTypes =arrMediaTypes;
//最长录制时间
picker.videoMaximumDuration =60;
picker.delegate =self;
//视频质量
picker.videoQuality =UIImagePickerControllerQualityTypeMedium;
//摄像头捕获模式
picker.cameraCaptureMode =UIImagePickerControllerCameraCaptureModeVideo;
//前置或后置摄像头
picker.cameraDevice =UIImagePickerControllerCameraDeviceRear;
//闪光灯模式
picker.cameraFlashMode =UIImagePickerControllerCameraFlashModeOff;
[self presentViewController:picker animated:YES completion:nil];
</pre><pre code_snippet_id="1595653" snippet_file_name="blog_20160303_3_7660880" name="code" class="objc">- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)infos {
NSURL *url=[infos objectForKey:UIImagePickerControllerMediaURL];//视频路径
NSString *urlStr=[url path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(urlStr)) {
//保存视频到相簿,注意也可以使用ALAssetsLibrary来保存
UISaveVideoAtPathToSavedPhotosAlbum(urlStr, self, nil, nil);//保存视频到相簿
}
[picker dismissViewControllerAnimated:YES completion:nil];
</pre><span style="font-size:24px">视频播放</span><pre>
moviePlayer =[[MPMoviePlayerController alloc]initWithContentURL:[imageDic objectForKey:@"videopath"]];
moviePlayer.view.layer.cornerRadius =8;
moviePlayer.view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[videoView addSubview:moviePlayer.view];
moviePlayer.fullscreen =YES;
[moviePlayer play];
截屏
//获取截图
-(void)getThumImage
{
AVURLAsset *asset =[[AVURLAsset alloc]initWithURL:[imageDic objectForKey:@"videopath"] options:nil];
AVAssetImageGenerator *gen =[[AVAssetImageGenerator alloc]initWithAsset:asset];
gen.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(0.0, 600);
NSError *error = nil;
CMTime actualTime;
CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
thumImage = [[UIImage alloc] initWithCGImage:image];
CGImageRelease(image);
}