Reputation: 113
I got thumbnail from video in photo library, now I want add duration and camera icon on the thumbnail like image . Have any suggestion? thanks.
Upvotes: 1
Views: 2088
Reputation: 49710
You can get duration of vide while you are selecting video file from Library like this:-
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
selectedVideoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
AVPlayerItem *SelectedItem = [AVPlayerItem playerItemWithURL:selectedVideoUrl];
CMTime duration = SelectedItem.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(@"duration: %.2f", seconds);
}
And you can get thumb of Video using :-
-(UIImage *)getThumbNail:(NSString*)stringPath
{
//stringPath is a path of stored video file from document directory
NSURL *videoURL = [NSURL fileURLWithPath:stringPath];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
//Player autoplays audio on init
[player stop];
return thumbnail;
}
now you have both you just need to create you custom view and do what you want.
Do Not forget to add
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
#import <AVFoundation/AVAsset.h>
Here also one nice answer that suitable with your issue Please check Bellow:-
iOS: get video duration and thumbnails without playing video
Upvotes: 4