iPhone :How to get duration of video selected from library?

前端 未结 6 1287
一整个雨季
一整个雨季 2020-12-23 12:14

I am using UIImagePickerController to choose video file from library. And user can upload the video.

Also I am using videoMaximumDuration p

6条回答
  •  清歌不尽
    2020-12-23 13:02

    The other answer to this question using AVPlayerItem didn't work for me, but this did using AVURLAsset:

    #import 
    
    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        NSURL *videoURL=[info objectForKey:@"UIImagePickerControllerMediaURL"];
        AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
    
        NSTimeInterval durationInSeconds = 0.0;
        if (asset)
            durationInSeconds = CMTimeGetSeconds(asset.duration);
    }
    

提交回复
热议问题