So, I want my application to edit and save ID3 tags. I found on some site many years ago about how to read them, here is this code in my application:
-(NSDictionary*)MP3InfoDictionary { AudioFileID fileID = nil; OSStatus err = noErr; err = AudioFileOpenURL( (CFURLRef) self, kAudioFileReadPermission, 0, &fileID); if (err != noErr) { //NSLog(@"AudioFileOpenURL failed"); } UInt32 id3DataSize = 0; char * rawID3Tag = NULL; err = AudioFileGetPropertyInfo(fileID, kAudioFilePropertyID3Tag, &id3DataSize, NULL); if (err != noErr) { NSLog(@"AudioFileGetPropeetyInfo failed for ID3 tag"); } //NSLog(@"id3 data size is %lu bytes",id3DataSize); rawID3Tag = (char *) malloc(id3DataSize); if (rawID3Tag == NULL) { //NSLog(@"could not allocated %lu bytes of memory for ID3 tag", id3DataSize); } err = AudioFileGetProperty(fileID, kAudioFilePropertyID3Tag, &id3DataSize, rawID3Tag); if (err != noErr) { NSLog(@"AudioFileGetProperty failed for ID3 tag"); } //NSLog(@"read %lu bytes of ID3 info", id3DataSize); CFDictionaryRef piDict = nil; UInt32 piDataSize = sizeof(piDict); free(rawID3Tag); err = AudioFileGetProperty(fileID, kAudioFilePropertyInfoDictionary, &piDataSize, &piDict); if (err != noErr) { //NSLog(@"AudioFileGetProperty failed for property info dictionary"); } //NSLog(@"Property info:%@", (NSDictionary*)piDict); //CFShow(piDict); NSDictionary *MP3InfoDictionary = (NSDictionary*)piDict; if (MP3InfoDictionary != NULL) { return MP3InfoDictionary; } return nil; }
This code is in the NSURL category, url is the URL of the mp3 file in the iOS document directory. It works 100%, I get all the names, works of art, lyrics, etc. But now I want to save and rewrite the values โโof mp3, as an artist, title, etc. In another post here, the guy posted that you are using AudioFileSetProperty (), how can I use it correctly?
Apparently this is due to kAudioFileReadPermission, but it tells me that mp3 is read-only, but that may not be true, because the other application that I have can change ID3 tags and can on the same mp3. which I tried to edit.