Correct encoding for ID3 Tags in iOS

我的梦境 提交于 2020-01-14 06:52:09

问题


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

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

If the tag doesn't contain cyrillic symbols, the output looks OK on the device. However I sometimes get values like this one:

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

and it leads to distorted symbols display (http://d.pr/i/X9wG).

Is there any way to decode these symbols into a readable form? I've already tried

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

but the result stays the same.

Any help will be greatly appreciated!

[UPDATE]

I tend to try a solution provided in this SO answer, but are there any other ways?


回答1:


That's way to decode these symbols into a readable form:

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


来源:https://stackoverflow.com/questions/16001847/correct-encoding-for-id3-tags-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!