2011-11-06 49 views
1

我想获得用户选择的视频长度。即时通讯使用苹果UIImagePicker,取消UIImagePicker后获取视频的长度?

这里是我到目前为止的代码:

[self dismissModalViewControllerAnimated:YES]; 
//assign the mediatype to a string 
//check the media type string so we can determine if its a video 
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; 
    webData = [[NSData alloc]init]; 
    webData = [NSData dataWithContentsOfURL:videoURL]; 
    //[self post:webData]; 
    video = 1; 
    upload.hidden = NO; 

    ImagesCopy = [[NSMutableArray alloc]initWithObjects:@"1", nil]; 
[tableview reloadData]; 

感谢:d

+0

此链接可以帮助你 HTTP ://stackoverflow.com/questions/1616146/getting-duration-of-video-taken-by-camera-iphone-sdk – Naveen

回答

6

你可以做到这一点

AVAsset *movie = [AVAsset assetWithURL:[info objectForKey:UIImagePickerControllerMediaURL]]; 
CMTime movieLength = movie.duration; 
+0

好吧,我将如何去NSLogging呢?我NSLogged它是一个%我得到了一个19秒的视频600。我也尝试NSLogging它%@和崩溃。我想能够将其转换为秒。感谢您的答案btw。 – Jacob

+0

看看这里: http://stackoverflow.com/questions/4001755/trying-to-understand-cmtime-and-cmtimemake – Rich86man

+0

明白了。谢谢! – Jacob