2016-10-10 124 views
0

我想從一個電影,我把我的iPhone/iPad上的時間,日期和地點獲得ALAssets這是我用從照片庫中的iOS

代碼//我得到的視頻挑選,然後保存它應用程序,但我想我得到電影的資產數據,然後我保存它。

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ NSError *error; 
else if (picker.sourceType ==UIImagePickerControllerSourceTypePhotoLibrary) { 

    NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ; 
    ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init]; 
    [assetslibrary assetForURL:movieURL 
        resultBlock:^(ALAsset*asset) { 
         NSDate *myDate = [asset valueForProperty:ALAssetPropertyDate]; 
         NSLog(@"Date: %@", myDate); 

        } failureBlock:^(NSError *error) { 
         NSLog(@"Error"); 
        }]; 
    NSData * movieData = [NSData dataWithContentsOfURL:movieURL]; 
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [documentPaths objectAtIndex:0]; 
    NSString *slash = [documentsDirectory stringByAppendingPathComponent:@"/"]; 
    NSString *documentsDirectory2 = [slash stringByAppendingPathComponent:self.user.text]; 
    NSString *documentsDirectory21 = [documentsDirectory2 stringByAppendingPathComponent:@"/Movie"]; 
    if (![[NSFileManager defaultManager] fileExistsAtPath:documentsDirectory21]) 
     [[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory21 withIntermediateDirectories:NO attributes:nil error:&error]; 
    NSString *fullPath = [documentsDirectory21 stringByAppendingPathComponent:[[self imageNameTextField]text]]; 
    fullPath = [fullPath stringByAppendingFormat:@".mp4"]; 
    [ movieData writeToFile:fullPath atomically:YES]; 
} 

然而指明MyDate被記錄爲空

我在做什麼錯

我只是嘗試這種代碼也(加入10/11)

CGImageSourceRef源= CGImageSourceCreateWithURL((CFURLRef) movieURL,NULL);

NSDictionary* metadata = (NSDictionary *)CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source,0,NULL)); 
    NSLog(@"image data %@", metadata); 

但仍然元數據爲空;

我看到視頻沒有與圖像相同的元數據。如果這是真的,那麼我如何訪問視頻元數據,因爲我可以看到與照片中的視頻相關的數據。

任何幫助,將不勝感激。

我已經嘗試了一切,我可以在互聯網上找到幫助我這樣做,但似乎沒有任何工作。 當我登錄我movieURL這是我得到

2016-10-13 09:58:51.045271 my little world app[2641:1388034]  movieURL;file:///private/var/mobile/Containers/Data/Application/22A178E5-74C4- 48EF-B487-5E01321508AD/tmp/trim.04F0AC8A-2960-464D-8670-7E79662EAB9B.MOV 

所以,因爲它是在一個臨時文件,我沒有得到的元數據。

元數據是否在電影NSData中退出,我可以從中獲得它嗎?

我拉我的頭髮。

回答

0

所以我想通了這一點這裏是代碼

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 

{ 
if (picker.sourceType ==UIImagePickerControllerSourceTypePhotoLibrary) { 
NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ; 
[self getMediaName:nil url:[info objectForKey:UIImagePickerControllerReferenceURL]]; 
} 
} 
- (void)getMediaName:(UIImage*)originalImage url:(NSURL*)url { 
    @try { 
     ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset) { 
      if (asset == nil) return; 
      ALAssetRepresentation *assetRep = [asset defaultRepresentation]; 
      NSString *fileName = [assetRep filename]; 
NSDate *myDate = [asset valueForProperty:ALAssetPropertyDate]; 
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init]; 
      [dateFormatter setDateFormat:@"MM-dd-yyyy"]; 
      NSLog(@"%@",[dateFormatter stringFromDate:myDate]); 
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *error) { 

     }; 

     ALAssetsLibrary *library = [ALAssetsLibrary new]; 
     [library assetForURL:url resultBlock:resultblock failureBlock:failureblock]; 
    } 
    @catch (NSException *exception) { 

    } 
} 

你可以使用任何valueForProperty