how can i get the video'a total time, before it plays the video in MPMoviePlayerViewController?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With