在我的应用中,我录制了视频&还在iphone中显示缩略图。一切正常。
但我的缩略图并未显示视频时长。
我从以下链接获得了代码:
//my code
NSURL *videoURL = [NSURL fileURLWithPath:url];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
我该如何解决这个问题?
答案 0 :(得分:2)
NSURL *videoURL = [NSURL fileURLWithPath:url];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showDuration:) name:MPMovieDurationAvailableNotification object:player];
-(void)showDuration:(NSNotification*)notif
{
MPMoviePlayerController *player = (MPMoviePlayerController*)[notif object];
NSLog(@"content play length is %g seconds", player.duration);
}