Avmetadataitem从iOS上的iTunes或ID3元数

Avmetadataitem从iOS上的iTunes或ID3元数

本文介绍了Avmetadataitem从iOS上的iTunes或ID3元数据获取trackNumber的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试获取aac,mp3或mp4文件的trackNumber。它不在commonMetadata中,所以我开始在其他元数据键中插入。我发现了一些看起来像它的东西,但我还是无法阅读它,并理解它。即使是原始数据对我也没有意义。

I'm trying to get the trackNumber of a aac, mp3 or mp4 file. It's not in the commonMetadata so I started to spelunk in the other metadata keys. I found something that looks like it, but I'm yet unable to read it, and make sense of it. Even the raw data makes no sense to me.

目前,我只是想尝试使用这个基本代码:

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

知道我正在寻找AVMetadataiTunesMetadataKeyTrackNumber。

Knowing I'm looking for AVMetadataiTunesMetadataKeyTrackNumber.

推荐答案

我意识到这个帖子很老了,但我最近自己遇到过这个问题。我需要所有可以收集的元数据并提出以下解决方案。它不是最优雅的解决方案,但它运作良好。写在Swift。

I realize this thread is quite old but I recently came across this issue myself. I needed ALL the metadata I could gather and came up with the following solution. It's not the most elegant solution but it works well enough. Written in 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)") }
        }
    }
}

这篇关于Avmetadataitem从iOS上的iTunes或ID3元数据获取trackNumber的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:47