ios 视频录制与播放

视频录制

//拍小视屏
            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);
}



 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值