2012-10-14 30 views
22

Tôi đã xem xét mọi ví dụ tôi có thể tìm để thiết lập dữ liệu meta bằng cách sử dụng AVAssetExportSession, nhưng mặc dù xuất âm thanh hoạt động tốt (tệp âm thanh kết quả phát OK), vẫn không có dữ liệu meta được xuất với tệp. Tôi đang sử dụng Xcode 4.5, mục tiêu xây dựng iOS 5, thử nghiệm thiết bị iOS 6. Vui lòng xem mã tôi đang sử dụng bên dưới và vui lòng cho tôi biết tôi đang làm gì sai.Cách sử dụng đúng AVAssetExportSession để đặt siêu dữ liệu cho nội dung âm thanh?

tiêu đề

// for metadata export 

NSArray *MyMetadata; 
AVMutableMetadataItem *common1; 
AVMutableMetadataItem *common2; 
AVMutableMetadataItem *common3; 
AVMutableMetadataItem *common4; 

thực hiện

AVAsset *asset = [AVAsset assetWithURL:audioFileInput]; 
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:asset presetName:AVAssetExportPresetPassthrough]; 

if (!exportSession) { 
    return; 
} 

CMTime startTime = CMTimeMake((int)(floor(fileStartMarker * 100)), 100); 
CMTime stopTime = CMTimeMake((int)(ceil(fileEndMarker * 100)), 100); 
CMTimeRange exportTimeRange = CMTimeRangeFromTimeToTime(startTime, stopTime); 

exportSession.outputURL = audioFileOutput; 
exportSession.outputFileType = @"com.apple.coreaudio-format"; 
exportSession.timeRange = exportTimeRange; 

// define meta data for file 
// Common metadata 
common1 = [[AVMutableMetadataItem alloc] init]; // Title 
common1.keySpace = AVMetadataKeySpaceCommon; 
common1.key = AVMetadataCommonKeyTitle; 
common1.value = @"Title Test Value"; 

common2 = [[AVMutableMetadataItem alloc] init]; // Description 
common2.keySpace = AVMetadataKeySpaceCommon; 
common2.key = AVMetadataCommonKeyDescription; 
common2.value = @"Description Test Value"; 

common3 = [[AVMutableMetadataItem alloc] init]; // Creation Date 
common3.keySpace = AVMetadataKeySpaceCommon; 
common3.key = AVMetadataCommonKeyCreationDate; 
common3.value = @"Creation Date Test Value"; 

common4 = [[AVMutableMetadataItem alloc] init]; // Software 
common4.keySpace = AVMetadataKeySpaceCommon; 
common4.key = AVMetadataCommonKeySoftware; 
common4.value = @"My File Trimmer"; 

MyMetadata = [[NSArray alloc] initWithObjects:common1, common2, common3, common4, nil]; 
exportSession.metadata = MyMetadata; 

[common1 release]; 
[common2 release]; 
[common3 release]; 
[common4 release]; 

[exportSession exportAsynchronouslyWithCompletionHandler:^{ 
    if (exportSession.status == AVAssetExportSessionStatusCompleted) { 
     // export done 
    } 
    else if (exportSession.status == AVAssetExportSessionStatusFailed)  { 
     // export failed 
    } 
}]; 

[MyMetadata release]; 
+0

Cập nhật: Sử dụng mã tương tự, nhưng thay vì xuất khẩu CAF, nếu tôi xuất khẩu sang M4A xuất khẩu siêu dữ liệu tốt. – user15209

+0

siêu dữ liệu là gì và nó được sử dụng để làm gì? – jgvb

+1

@ user15209 bạn nên thêm nhận xét của mình làm câu trả lời và chấp nhận –

Trả lời

1

Bạn đã cố gắng thiết lập các định danh?

như:

let authorMeta = AVMutableMetadataItem() 
    authorMeta.identifier = AVMetadataCommonIdentifierAuthor 
    authorMeta.key = AVMetadataQuickTimeMetadataKeyAuthor 
    authorMeta.keySpace = AVMetadataKeySpaceCommon 
    authorMeta.value = "NFer" 
Các vấn đề liên quan