更改AVMetadataItem

我有一些文件,-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]; 

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