我正在捕捉视频它工作正常,但我想获取该视频的缩略图并在 ImageView 中显示它任何想法如何在下面得到这个是我的代码。
if ([type isEqualToString:(NSString *)kUTTypeVideo] || [type isEqualToString:(NSString *)kUTTypeMovie])
{
NSURL*videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(@"found a video");
videoData = [[NSData dataWithContentsOfURL:videoURL] retain];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
[dateFormat setDateFormat:@"dd-MM-yyyy_HH:mm:SS"];
NSDate *now = [[[NSDate alloc] init] autorelease];
NSDate* theDate = [dateFormat stringFromDate:now];
NSString*myDate=[dateFormat stringFromDate:theDate];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"Default Album"];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil];
NSString*test=@"test";
NSString*testUser=[test stringByReplacingOccurrencesOfString:@" " withString:@""];
videopath= [[[NSString alloc] initWithString:[NSString stringWithFormat:@"%@/%@.mov",documentsDirectory,testUser]] autorelease];
BOOL success = [videoData writeToFile:videopath atomically:NO];
NSLog(@"Successs:::: %@", success ? @"YES" : @"NO");
NSLog(@"video path --> %@",videopath);
NSURL *movieURL = [NSURL fileURLWithPath:videopath];
AVURLAsset *avUrl = [AVURLAsset assetWithURL:movieURL];
CMTime time = [avUrl duration];
int seconds = ceil(time.value/time.timescale);
// durationTime=[NSString stringWithFormat:@"%d",seconds];
// insertTime=[NSString stringWithFormat:@"%d",seconds];
NSString*messageA=[NSString stringWithFormat:@"You have recorded video of duration of %d seconds ",seconds];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:messageA
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
NSDate* date = [NSDate date];
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:MM:SS"];
//[formatter setDateFormat:@"MM-dd-yyyy"];
NSString* str = [formatter stringFromDate:date];