2011-11-06 31 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