我试图从照片库中选择/压缩视频,但是当我去获取持续时间和创建日期时,它们都返回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];
}
}
答案 0 :(得分:3)
根据documentation,UIImagePickerControllerMediaMetadata
仅对静止图像有效:
此密钥仅在使用源类型为的图像选择器时有效 设置为UIImagePickerControllerSourceTypeCamera,仅适用于 静止图像。
为了获得您想要的元数据,请使用ALAsset
和metadata方法。