Exemplo n.º 1
0
sp<MetaData> MP3Extractor::getMetaData() {
    sp<MetaData> meta = new MetaData;

    if (mInitCheck != OK) {
        return meta;
    }

    meta->setCString(kKeyMIMEType, "audio/mpeg");

    ID3 id3(mDataSource, false);

    if (!id3.isValid()) {
        return meta;
    }

    struct Map {
        int key;
        const char *tag1;
        const char *tag2;
    };
    static const Map kMap[] = {
        { kKeyAlbum, "TALB", "TAL" },
        { kKeyArtist, "TPE1", "TP1" },
        { kKeyAlbumArtist, "TPE2", "TP2" },
        { kKeyComposer, "TCOM", "TCM" },
        { kKeyGenre, "TCON", "TCO" },
        { kKeyTitle, "TIT2", "TT2" },
        { kKeyYear, "TYE", "TYER" },
        { kKeyAuthor, "TXT", "TEXT" },
        { kKeyCDTrackNumber, "TRK", "TRCK" },
        { kKeyDiscNumber, "TPA", "TPOS" },
        { kKeyCompilation, "TCP", "TCMP" },
    };
    static const size_t kNumMapEntries = sizeof(kMap) / sizeof(kMap[0]);

    for (size_t i = 0; i < kNumMapEntries; ++i) {
        ID3::Iterator *it = new ID3::Iterator(id3, kMap[i].tag1);
        if (it->done()) {
            delete it;
            it = new ID3::Iterator(id3, kMap[i].tag2);
        }

        if (it->done()) {
            delete it;
            continue;
        }

        String8 s;
        it->getString(&s);
        delete it;

        meta->setCString(kMap[i].key, s);
    }

    size_t dataSize;
    String8 mime;
    const void *data = id3.getAlbumArt(&dataSize, &mime);

    if (data) {
        meta->setData(kKeyAlbumArt, MetaData::TYPE_NONE, data, dataSize);
        meta->setCString(kKeyAlbumArtMIME, mime.string());
    }

    return meta;
}
Exemplo n.º 2
0
sp<MetaData> APEExtractor::getMetaData()
{
    LOGV("APEExtractor::getMetaData()");
    sp<MetaData> meta = new MetaData;

    if (mInitCheck != OK)
    {
        return meta;
    }

    meta->setCString(kKeyMIMEType, "audio/ape");

    ID3 id3(mDataSource);

    if (id3.isValid())
    {
        LOGE("APEExtractor::getMetaData() ID3 id3");
        struct Map
        {
            int key;
            const char *tag1;
            const char *tag2;
        };
        static const Map kMap[] =
        {
            { kKeyAlbum, "TALB", "TAL" },
            { kKeyArtist, "TPE1", "TP1" },
            { kKeyAlbumArtist, "TPE2", "TP2" },
            { kKeyComposer, "TCOM", "TCM" },
            { kKeyGenre, "TCON", "TCO" },
            { kKeyTitle, "TIT2", "TT2" },
            { kKeyYear, "TYE", "TYER" },
            { kKeyAuthor, "TXT", "TEXT" },
            { kKeyCDTrackNumber, "TRK", "TRCK" },
            { kKeyDiscNumber, "TPA", "TPOS" },
            { kKeyCompilation, "TCP", "TCMP" },
        };
        static const size_t kNumMapEntries = sizeof(kMap) / sizeof(kMap[0]);

        for (size_t i = 0; i < kNumMapEntries; ++i)
        {
            ///LOGE("getMetaData() id3 kMap %d, %d", kNumMapEntries, i);
            ID3::Iterator *it = new ID3::Iterator(id3, kMap[i].tag1);

            if (it->done())
            {
                delete it;
                it = new ID3::Iterator(id3, kMap[i].tag2);
            }

            if (it->done())
            {
                delete it;
                continue;
            }

            String8 s;
            it->getString(&s);
            delete it;

            meta->setCString(kMap[i].key, s);
        }

        size_t dataSize;
        String8 mime;
        const void *data = id3.getAlbumArt(&dataSize, &mime);

        if (data)
        {
            meta->setData(kKeyAlbumArt, MetaData::TYPE_NONE, data, dataSize);
            meta->setCString(kKeyAlbumArtMIME, mime.string());
        }

        return meta;

    }

    APETAG apetag(mDataSource);

    if (apetag.isValid())
    {

        struct ApeMap
        {
            int key;
            const char *tag;
            uint16_t    key_len;
            uint32_t    key_attr;
        };
        static const ApeMap kMap[] =
        {
            { kKeyAlbum,        "Album",    5,  META_TAG_ATTR_ALBUM },
            { kKeyArtist,       "Artist",   6,  META_TAG_ATTR_ARTIST },
            { kKeyComposer,     "Composer", 7,  META_TAG_ATTR_AUTHOR },
            { kKeyGenre,        "Genre",    5,  META_TAG_ATTR_GENRE },
            { kKeyTitle,        "Title",    5,  META_TAG_ATTR_TITLE },
            { kKeyYear,         "Year",     4,  META_TAG_ATTR_YEAR },
            { kKeyCDTrackNumber, "Track",    5,  META_TAG_ATTR_TRACKNUM },
        };

        static const size_t kNumMapEntries = sizeof(kMap) / sizeof(kMap[0]);

        for (size_t i = 0; i < kNumMapEntries; ++i)
        {
            APETAG::Iterator *it = new APETAG::Iterator(apetag, kMap[i].tag, kMap[i].key_len);

            if (it->done())
            {
                delete it;
                continue;
            }

            String8 s;
            it->getString(&s);
            delete it;

            meta->setCString(kMap[i].key, s);
        }

        return meta;

    }

    return meta;


}