这个问题相当老了,但我遇到了类似的问题,所以对于仍然需要解决方案的人来说。我设法找出使用以下代码获取总曲目编号和曲目编号的方法:
NSString *value = @"<0000000a 00140000>" //[item stringValue] (in this case 10/20)
NSString *track_no_hex = [[value componentsSeparatedByString:@" "][0] stringByReplacingOccurrencesOfString:@"<" withString:@""];
NSString *total_track_no_hex = [[value componentsSeparatedByString:@" "][1] stringByReplacingOccurrencesOfString:@">" withString:@""];
NSString *track_no = @"";
for(int k=0;k<=4;k+=4){
unsigned result = 0;
NSScanner *scanner = [NSScanner scannerWithString:[track_no_hex substringWithRange:NSMakeRange(k, 4)]];
[scanner scanHexInt:&result];
if(result == 00){
}
else{
track_no = [NSString stringWithFormat:@"%@%u",track_no,result];
}
}
NSString *total_track_no = @"";
for(int k=0;k<=4;k+=4){
unsigned result = 0;
NSScanner *scanner;
if(k+4<=[total_track_no_hex length]){
scanner = [NSScanner scannerWithString:[total_track_no_hex substringWithRange:NSMakeRange(k, 4)]];
}
else{
}
[scanner scanHexInt:&result];
if(result == 00){
}
else{
total_track_no = [NSString stringWithFormat:@"%@%u",total_track_no,result];
}
}
NSLog(@"%@/%@",track_no, total_track_no); // Output 10/20
这适用于 14461 以下的曲目编号,考虑到 iTunes 最大曲目编号为 999,曲目编号应该足够大。