2

i want to get the length of a video that the user picks. Im using apples UIImagePicker,

here is my code so far:

    [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];

Thanks :D

Jacob
  • 1,459
  • 2
  • 19
  • 32
  • This link may help you http://stackoverflow.com/questions/1616146/getting-duration-of-video-taken-by-camera-iphone-sdk – Naveen Nov 06 '11 at 08:03

1 Answers1

7

You can do this

AVAsset *movie = [AVAsset assetWithURL:[info objectForKey:UIImagePickerControllerMediaURL]];
CMTime movieLength = movie.duration;
Rich86man
  • 6,507
  • 2
  • 26
  • 27
  • Okay, and how would i go about NSLogging that? i NSLogged it as a %i and got 600 for a 19 second video. I also tried NSLogging it as a %@ and crashed. I want to be able to convert this to seconds. Thanks for your answer btw. – Jacob Nov 07 '11 at 02:42
  • Take a look here : http://stackoverflow.com/questions/4001755/trying-to-understand-cmtime-and-cmtimemake – Rich86man Nov 07 '11 at 06:13