0

我正在尝试从照片库中选择/压缩视频,但是当我获取持续时间和创建日期时,它们都返回 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];

 }
}
4

1 回答 1

3

根据文档UIImagePickerControllerMediaMetadata仅对静止图像有效:

此键仅在使用源类型设置为 UIImagePickerControllerSourceTypeCamera 的图像选择器时有效,并且仅适用于静止图像。

为了得到你想要的元数据,使用ALAssetmetadata方法。

于 2013-01-22T08:39:43.283 回答