Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone MPMoviePlayerViewController : extract total duration

how can i get the video'a total time, before it plays the video in MPMoviePlayerViewController?

like image 744
Shefali Soni Avatar asked Dec 21 '22 03:12

Shefali Soni


1 Answers

To get total duration of movie you can use :

1). Use AVPlayerItem class and AVFoundation and CoreMedia framework. (I have used UIImagePickerController for picking the movie)

#import <AVFoundation/AVFoundation.h>
#import <AVFoundation/AVAsset.h>

- (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);
}

2). MPMoviePlayerController has a property duration .Refer Apple Doc

like image 80
Maulik Avatar answered Feb 23 '23 01:02

Maulik