ios - 如何正确使用 AVAssetExportSession 为音频 Assets 设置元数据?

标签 ios audio metadata avassetexportsession

我已经查看了我能找到的使用 AVAssetExportSession 设置元数据的每个示例,但即使音频导出工作正常(生成的音频文件播放正常),仍然没有导出元数据文件。我正在使用 Xcode 4.5,目标构建 iOS 5,测试设备 iOS 6。请查看下面我使用的代码,请告诉我我做错了什么。

标题

// for metadata export

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

实现

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];

最佳答案

您是否尝试过设置标识符?

喜欢:

    let authorMeta = AVMutableMetadataItem()
    authorMeta.identifier = AVMetadataCommonIdentifierAuthor
    authorMeta.key = AVMetadataQuickTimeMetadataKeyAuthor
    authorMeta.keySpace = AVMetadataKeySpaceCommon
    authorMeta.value = "NFer"

关于ios - 如何正确使用 AVAssetExportSession 为音频 Assets 设置元数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12879596/

相关文章:

iOS-向应用程序窗口添加导航栏

android - 如何跨多个设备缩放用户提供的图像

mysql - 在 MySQL 中循环以创建串联变量

c# - 为什么 VS 元数据 View 不显示显式接口(interface)实现的成员

ios - 在其自身初始值内使用的变量

java - gwt-voices - wav 文件未播放

r - 从一个大型(350 mb).wav制成的S4对象中输出许多.wav,这些内容分为5秒

javascript - 如何使用 javascript 从 Audio Element 录制音频

.net - 为什么自定义属性同时出现在 IL 和 Metadata 中?

ios - 具有分组表问题的 commitEditingStyle