5

I'm having difficulties writing a audio file's metadata:

AudioFileID fileID = nil;
AudioFileOpenURL((__bridge CFURLRef) url, kAudioFileReadWritePermission, 0, &fileID );
CFDictionaryRef piDict = nil;
UInt32 piDataSize   = sizeof(piDict);   
AudioFileGetProperty( fileID, kAudioFilePropertyInfoDictionary, &piDataSize, &piDict );
NSLog(@"%@", (__bridge NSDictionary *)piDict);

NSMutableDictionary *dict = (__bridge NSMutableDictionary*)piDict;
[dict setObject:@"NEW ALBUM NAME" forKey:@"album"];
piDict = (__bridge CFDictionaryRef)dict;
piDataSize = sizeof(dict);
OSStatus status = AudioFileSetProperty(fileID, kAudioFilePropertyInfoDictionary, piDataSize, &piDict);

The NSLog on line #6 gives me a nice dictionary with ID3 information. But when I want to alter (for instance the album name, line #9) I get an OSStatus 'pty?' in return.

Anyone who can give me pointers on what I'm doing wrong. Or maybe even a better / simpler / quicker way to edit ID3 tags / metadata for audio files.

justin
  • 104,054
  • 14
  • 179
  • 226
basvk
  • 4,437
  • 3
  • 29
  • 49

1 Answers1

4

Doing almost the same thing here. You can check the OSStatus error with the following code.

NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil];
NSLog(@"Error: %@", [error description]);

And what I got is:

Error: Error Domain=NSOSStatusErrorDomain Code=1886681407 "The operation couldn’t be completed. (OSStatus error 1886681407.)"

Could it be that iOS just doesn't allow you to modify kAudioFilePropertyInfoDictionary?


Update:

I just ported idlib3 to iOS and you can use it to modify the ID3 tag. An example project is also included. Check it here https://github.com/rjyo/libid3-ios

rjyo
  • 226
  • 1
  • 5
  • I don't know. Can't find any documentation about the limitations of AudioFileSetProperty. The other Core audio methods work perfectly on iOS. – basvk Jan 24 '12 at 14:00
  • 2
    I just ported idlib3 to iOS and you can use it to modify the ID3 tag. An example project is also included. Check it here https://github.com/rjyo/libid3-ios – rjyo Feb 02 '12 at 08:32
  • Thanks @Lele Xu, I'll check it out. – basvk Feb 02 '12 at 15:53