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

前端 未结 6 1284
一整个雨季
一整个雨季 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:10

    Got the solution : I use AVPlayerItem class and AVFoundation and CoreMedia framework.

    #import 
    #import 
    
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        selectedVideoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
    
        AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:selectedVideoUrl];
    
        CMTime duration = playerItem.duration;
        float seconds = CMTimeGetSeconds(duration);
        NSLog(@"duration: %.2f", seconds);
    }
    

提交回复
热议问题