2013-02-20 24 views
9

Tôi đang cố gắng lưu video có siêu dữ liệu tùy chỉnh có liên quan cho ứng dụng của mình và cố truy xuất nó khi người dùng chọn video đó từ thư viện. Tôi không chắc liệu tôi có đang lưu siêu dữ liệu ngay khi tôi không thể thấy bất cứ điều gì khi tôi cố gắng truy xuất siêu dữ liệu. Tôi cũng không chắc chắn nếu tôi lấy dữ liệu meta chính xác. Tôi mới sử dụng iOS, mọi trợ giúp đều được đánh giá cao. Tôi đã tìm kiếm nhiều chủ đề và thư viện nhà phát triển nhưng không thể làm được điều này.Làm cách nào để thêm và truy xuất dữ liệu meta tùy chỉnh vào tệp video trong lập trình iOS?

Tôi đang cố gắng lưu siêu dữ liệu trong hàm ủy nhiệmDidFinishToOutputFileURL. Video đang được lưu trong thư viện.

NSMutableArray *metadata = [NSMutableArray array]; 
    AVMutableMetadataItem *mi = [AVMutableMetadataItem metadataItem]; 
    mi.key = AVMetadataCommonKeyTitle; 
    mi.keySpace = AVMetadataKeySpaceCommon; 
    mi.value = @"title"; 
    [metadata addObject:mi]; 

    NSLog(@"Output saving:%@",outputFileURL); 
    AVAsset *video = [AVAsset assetWithURL:outputFileURL]; 
    AVAssetExportSession *exportSession = [AVAssetExportSession  exportSessionWithAsset:video presetName:AVAssetExportPresetPassthrough]; 
    exportSession.shouldOptimizeForNetworkUse = YES; 
    exportSession.outputFileType = AVFileTypeMPEG4; 
    exportSession.metadata = metadata; 
    exportSession.outputURL = outputFileURL; 
    [exportSession exportAsynchronouslyWithCompletionHandler:^{ 
     NSLog(@"done processing video!"); 
     UISaveVideoAtPathToSavedPhotosAlbum(outputFileURL.path, self, @selector(video:didFinishSavingWithError: contextInfo:), nil); 
    }]; 

tôi đang cố gắng để truy xuất video trong chức năng đại biểu didFinishPickingMediaWithInfo để kiểm tra siêu dữ liệu nhưng không thể nhìn thấy bất cứ điều gì trong hàm completionhandler

 if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) { 
     video_selected = TRUE; 
     NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; 

     NSLog(@"video has %@", videoURL.path); 
     AVAsset *videoAsset = [AVAsset assetWithURL:videoURL]; 
     NSLog(@"Loading metadata..."); 
     NSArray *keys = [[NSArray alloc] initWithObjects:@"commonMetadata", nil]; 
     NSMutableArray *metadata = [[NSMutableArray alloc] init]; 
     [videoAsset loadValuesAsynchronouslyForKeys:keys completionHandler:^{ 

      [metadata removeAllObjects]; 
      for (NSString *format in [videoAsset availableMetadataFormats]) 
      { 
       [metadata addObjectsFromArray:[videoAsset metadataForFormat:format]]; 
       NSLog(@"Printing metadata-%@",metadata); 
      } 


     }]; 
+0

Bạn có thể lưu tệp vào máy tính thông thường để xem siêu dữ liệu ở đó không? – Liron

+0

tại sao bạn lại cố gắng thêm siêu dữ liệu thay vì tạo thư mục mới trong thư viện ảnh của mình? để bạn có thể lưu và truy xuất video/ảnh có liên quan đến ứng dụng của mình? – iremk

+0

Chỉ hỗ trợ loại tệp mov? không mp4 – crossle

Trả lời

0

kiểm tra lỗi của bạn. Bạn đang xuất khẩu đến nơi tệp đã tồn tại để nó xuất vào chính nó và sẽ không hoạt động. Chỉ cần xuất sang một vị trí khác

Các vấn đề liên quan