3

UIimagepickercontroller を介して取得した映画の作成日を取得するにはどうすればよいですか。次のコードを取得しましたが、作成日の情報がありません。ファイル属性も試しましたが、うまくいきませんでした。

NSURL *url = urlfromimagepicker;
NSDictionary *options = @{ AVURLAssetPreferPreciseDurationAndTimingKey : @YES };
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:options];

NSArray *metadata = [asset commonMetadata];
for ( AVMetadataItem* item in metadata ) {
    NSString *key = [item commonKey];
    NSString *value = [item stringValue];
    NSLog(@"key = %@, value = %@", key, value);
}
4

2 に答える 2

3
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];

    if(CFStringCompare((CFStringRef) mediaType,  kUTTypeMovie, 0) == kCFCompareEqualTo)
    {
        //Dismiss the media picker view
        [picker dismissModalViewControllerAnimated:YES];

        //Get the URL of the chosen content, then get the data from that URL
        NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
        NSData *webData = [NSData dataWithContentsOfURL:videoURL];

        //Gets the path for the URL, to allow it to be saved to the camera roll
        NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
        {
            ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];

            //The key UIImagePickerControllerReferenceURL allows you to get an ALAsset, which then allows you to get metadata (such as the date the media was created)
            [lib assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) {
                NSLog(@"created: %@", [asset valueForProperty:ALAssetPropertyDate]);
            } failureBlock:^(NSError *error) {
                NSLog(@"error: %@", error);
            }];
        }
    }
}

この質問を参照してください:UIImagePickerControllerによって作成/選択されたメディアを追跡するにはどうすればよいですか?

于 2012-11-02T05:38:06.920 に答える
1

ALAssetvalueForPropertyプロパティがあり、次のものが含まれています。

NSString *const ALAssetPropertyType;
NSString *const ALAssetPropertyLocation;
NSString *const ALAssetPropertyDuration;
NSString *const ALAssetPropertyOrientation;
NSString *const ALAssetPropertyDate;
NSString *const ALAssetPropertyRepresentations;
NSString *const ALAssetPropertyURLs;
NSString *const ALAssetPropertyAssetURL; 

このように使用します:

ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *myAsset){
     NSLog(@"created Date: %@",[myAsset valueForProperty:ALAssetPropertyDate]);
};
于 2012-11-02T05:38:35.990 に答える