iOS判断从系统相册选取的是视频还是照片

第一种方法:并可以获取到视频的缩略图,原文地址:http://blog.csdn.net/xiaobo16/article/details/7759181

- (void)imagePickerController:(UIImagePickerController *)picker   didFinishPickingMediaWithInfo:(NSDictionary *)info 
{   
    [picker dismissModalViewControllerAnimated:YES];
    
    NSString *mediaType = [infoobjectForKey:UIImagePickerControllerMediaType];
    if([mediaType isEqualToString:@"public.movie"])
    {
        NSURL *videoURL = [infoobjectForKey:UIImagePickerControllerMediaURL];
        NSLog(@"found a video");
        //获取视频的thumbnail     
        MPMoviePlayerController *player = [[[MPMoviePlayerControlleralloc]initWithContentURL:videoURL] autorelease];
        UIImage  *thumbnail = [playerthumbnailImageAtTime:1.0timeOption:MPMovieTimeOptionNearestKeyFrame];
player = nil;
        }
} 

第二种方法,通过判断是否含有视频轨道,参考地址:http://www.thinksaas.cn/ask/question/22483/

- (void)imagePickerController: (UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info{
    
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
    AVAsset *asset = [AVURLAsset URLAssetWithURL:videoURL options:info];
    NSArray *tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
    //判断是否含有视频轨道
    BOOL hasVideoTrack = [tracks count] > 0;
    if (hasVideoTrack) {
        [picker dismissViewControllerAnimated:YES completion:^{
            
        }];
        return;
    }
 }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值