6

我有一些文件,-m4a -mp4 -mp3 等。我想更改这些详细信息

  • AVMetadataItem
  • AVMetadataCommonKeyArtwork
  • AVMetadataCommonKeyArtist

我可以使用AVAssetExportSession,但我需要更改目录。请问有没有办法直接在文件上写?

我找到了这个程序,但不起作用:(

NSError *error;
AVAssetWriter *assetWrtr = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:self.path] fileType:AVFileTypeAppleM4A error:&error];
NSLog(@"%@",error);

NSArray *existingMetadataArray = assetWrtr.metadata;
NSMutableArray *newMetadataArray = nil;
if (existingMetadataArray)
{
    newMetadataArray = [existingMetadataArray mutableCopy]; // To prevent overriding of existing metadata
}
else
{
    newMetadataArray = [[NSMutableArray alloc] init];
}


 AVMutableMetadataItem *item = [[AVMutableMetadataItem alloc] init];
item.keySpace = AVMetadataKeySpaceCommon;
item.key = AVMetadataCommonKeyArtwork;
item.value = UIImagePNGRepresentation([[UIImage alloc] initWithContentsOfFile:[[NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@".image"]]);

[newMetadataArray addObject:item];
assetWrtr.metadata = newMetadataArray;



[assetWrtr startWriting];
[assetWrtr startSessionAtSourceTime:kCMTimeZero];
4

1 回答 1

4

UIImagePNGRepresentation更改 为UIImageJPEGRepresentation您需要 jpeg 数据而不是 png。

于 2014-09-04T11:31:24.340 回答