我正在尝试获取aac、mp3或mp4文件的trackNumber。它不在commonMetadata中,所以我开始拼写其他的元数据键。我找到了一些看起来像它的东西,但我仍然无法阅读它,也无法理解它。即使是原始数据对我来说也没有任何意义。
目前,我只想使用下面的基本代码来获得它:
NSArray *meta = [asset metadataForFormat:AVMetadataFormatiTunesMetadata];
for ( AVMetadataItem* item in meta ) {
id key = [item key];
NSString *value = [item stringValue];
NSLog(@"key = %@, value = %@", key, value);
}知道我在找AVMetadataiTunesMetadataKeyTrackNumber。
发布于 2014-07-09 04:53:32
我知道这个帖子已经很老了,但最近我自己也遇到了这个问题。我需要我能收集到的所有元数据,并提出了以下解决方案。这不是最优雅的解决方案,但已经足够好用了。用Swift写的。
func processFile(url:NSURL) {
let yearKey = -1453039239
let genreKey = -1452841618
let encoderKey = -1451987089
let trackKey = "com.apple.iTunes.iTunes_CDDB_TrackNumber"
let CDDBKey = "com.apple.iTunes.iTunes_CDDB_1"
let path:String = url.absoluteString
let asset = AVURLAsset(URL: url, options: nil)
let format = AVMetadataFormatiTunesMetadata
for item:AVMetadataItem in asset.metadataForFormat(format) as Array<AVMetadataItem> {
if let key = item.commonKey { if key == "title" { println(item.value()) } }
if let key = item.commonKey { if key == "artist" { println(item.value()) } }
if let key = item.commonKey { if key == "albumName" { println(item.value()) } }
if let key = item.commonKey { if key == "creationDate" { println(item.value()) } }
if let key = item.commonKey { if key == "artwork" { println( "art" ) } }
if item.key().isKindOfClass(NSNumber) {
if item.key() as NSNumber == yearKey { println("year: \(item.numberValue)") }
if item.key() as NSNumber == genreKey { println("genre: \(item.stringValue)") }
if item.key() as NSNumber == encoderKey { println("encoder: \(item.stringValue)") }
}
if item.key().isKindOfClass(NSString) {
if item.key() as String == trackKey { println("track: \(item.stringValue)") }
if item.key() as String == CDDBKey { println("CDDB: \(item.stringValue)") }
}
}
}发布于 2012-04-25 15:00:38
如果您的曲目有ID3元数据,您可以很容易地获得曲目编号的numberValue。如果你的曲目有iTunesMetadata,那么dataValue就是你得到的全部。您必须自己猜测intValue。
到目前为止,我在这里。我非常确定我需要在字节部分做更多的工作。
NSArray *meta = [asset metadataForFormat:AVMetadataFormatiTunesMetadata];
NSArray *itfilteredKeys = [AVMetadataItem metadataItemsFromArray:meta withKey:AVMetadataiTunesMetadataKeyTrackNumber keySpace:nil];
for ( AVMetadataItem* item in itfilteredKeys ) {
NSData *value = [item dataValue];
unsigned char aBuffer[4];
[value getBytes:aBuffer length:4];
unsigned char *n = [value bytes];
int value1 = aBuffer[3];
NSLog(@"trackNumber from iTunes = %i", value1);
}发布于 2013-07-04 16:48:13
这个问题很老了,但是我遇到了类似的问题,所以对于那些仍然需要解决方案的人来说。我设法找出了一种使用以下代码获取总曲目数量和曲目数量的方法:
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.
https://stackoverflow.com/questions/10292913
复制相似问题