我正在尝试从照片库中选择/压缩视频,但是当我获取持续时间和创建日期时,它们都返回 null(持续时间默认为 0.0 秒)。我不确定我是否在这里做错了什么。
- (void)imagePickerController:(UIImagePickerController *)uploadPick didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if (CFStringCompare (( CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)
{
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
//Video Duration:
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc]
initWithContentURL:videoURL];
VideoTime.text = [NSString stringWithFormat:@"Time: %.2f", mp.duration];
//Video Creation Date
NSDictionary *metadataDictionary = (NSDictionary *)[info valueForKey:UIImagePickerControllerMediaMetadata];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *stringDate = [dateFormatter stringFromDate:metadataDictionary.fileCreationDate];
[dateFormatter release];
VideoDateTaken.text = [NSString stringWithFormat:@"Date Taken: %@", stringDate];
}
}