Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 更改AVMetadataItem_Iphone_Ios_Objective C_Avassetwriter_Avmetadataitem - Fatal编程技术网

Iphone 更改AVMetadataItem

Iphone 更改AVMetadataItem,iphone,ios,objective-c,avassetwriter,avmetadataitem,Iphone,Ios,Objective C,Avassetwriter,Avmetadataitem,我有一些文件,-m4a-mp4-mp3等。 我想改变这些细节 AVMetadataItem AVMetadataCommonKeyArtwork avMetadataCommonKeyArtister 我可以使用AVAssetExportSession,但我需要更改目录。有没有办法我可以直接写在文件上 我找到了此程序,但不起作用:( 将UIImagePNGRepresentation更改为uiimagejpegresentation您需要的是jpeg数据,而不是png NSError *er

我有一些文件,-m4a-mp4-mp3等。 我想改变这些细节

  • AVMetadataItem
  • AVMetadataCommonKeyArtwork
  • avMetadataCommonKeyArtister
我可以使用
AVAssetExportSession
,但我需要更改目录。有没有办法我可以直接写在文件上

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


UIImagePNGRepresentation更改为uiimagejpegresentation您需要的是jpeg数据,而不是png

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