Fix encoding for ID3 tags in iOS

I am trying to get ID3 tags from a bunch of mp3 files in my project.

AudioFileGetProperty(audioFile, kAudioFilePropertyInfoDictionary, &size, &metadataDictionary); 

If the tag does not contain Cyrillic characters, the device’s appearance on the device looks normal. However, sometimes I get values ​​like this:

 album = "\U00ce\U00f2\U00ea\U00f0\U00fb\U00f2\U00ee\U00e5 \U00d0\U00e0\U00e4\U00e8\U00ee 102.5FM"; "approximate duration in seconds" = "260.623"; 

and this leads to the display of garbled characters ( http://d.pr/i/X9wG ).

Is there a way to decode these characters in readable form? I have already tried

 NSString* value = [metadataDictionary objectForKey: key]; NSData* data = [value dataUsingEncoding: NSASCIIStringEncoding]; NSString* string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]; 

but the result remains the same.

Any help would be greatly appreciated!

[UPDATE]

I try to try the solution presented in this SO answer , but are there any other ways?

0
source share
1 answer

Thus, to decode these characters in readable form:

 NSString *value = [metadataDictionary objectForKey:@"artist"]; const char *cString = [value cStringUsingEncoding:NSWindowsCP1252StringEncoding]; NSString *artist = [NSString stringWithCString:cString encoding:NSWindowsCP1251StringEncoding]; 
+1
source

Source: https://habr.com/ru/post/1401070/


All Articles