English 中文(简体)
A. Avmetadataitem 将轨数从SiOS的Atd 或ID3元数据上调
原标题:Avmetadataitem Getting the trackNumber from an iTunes or ID3 metadata on iOS

I m 试图获得ac、mp3或mp4文档的履带。 这不是在通用Meta数据中,因此,我开始在其他元数据钥匙中击退。 我发现了一些类似的东西,但我仍然无法读到,并且感觉到这一点。 甚至原始数据对我来说也毫无意义。

At the moment, I m just trying to get it using this basic code:

    NSArray *meta = [asset metadataForFormat:AVMetadataFormatiTunesMetadata];
    for ( AVMetadataItem* item in meta ) {
        id key = [item key];
        NSString *value = [item stringValue];
        NSLog(@"key = %@, value = %@", key, value);
    }

• 了解Im ,寻找ARVetadata CPDMetadataKeyTrackNumber。

问题回答

我认识到这一read已久,但我最近亲自来过这个问题。 我可以收集所有元数据,并提出以下解决办法。 这不是最棘手的解决办法,而是做得很好。 快速书写。

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)") }
        }
    }
}

If your track has ID3 metadata, you can easily get the numberValue for the track number. If your track has iTunesMetadata, the dataValue is all you get. You have to guess the intValue yourself.

到目前为止,我在这里开会。 我很相信,我需要更多地处理tes问题。

    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);
    }

This question is rather old, but I came upon it as I had a similar problem, so for anyone who still needs a solution. I managed to figure out a way of getting the total tracks number and the track number using the following code:

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项下的轨道编号进行罚款,鉴于UNV最大轨道号码为999,该数字应当足够大。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签