larsbs / id3v2lib

id3v2lib is a library written in C to read and edit id3 tags from mp3 files.
BSD 2-Clause "Simplified" License
128 stars 44 forks source link

It just doesn't read tags :-( #12

Closed hopeseekr closed 8 years ago

hopeseekr commented 8 years ago

Tell me why the following doesn't work!

#include <iostream>
#include <id3v2lib.h>

using std::cout;
using std::endl;

int main(int argc, char* argv[])
{
    ID3v2_header* header = get_tag_header(argv[1]);
    if (header != NULL) {
        cout << "Header is NOT NULL! Woohoo!!\n";
        if (has_id3v2tag(header)) {
            cout << "OMFG! The file has an ID3v2 tag!!" << endl;
        }
        else {
            cout << "Oh man! The file DOES NOT have an ID3v2 tag. :-(" << endl;
        }
    }
    else {
        cout << "Header is NULL!!\n";
    }

    ID3v2_tag* tag = load_tag(argv[1]);
    if (tag != NULL) {
        ID3v2_frame* title_frame = tag_get_title(tag);
        ID3v2_frame_text_content* content;

        content = parse_text_frame_content(title_frame);
        printf("Title: %s\n", content->data);
    }
    else {
        cout << "Tag is NULL!!\n";
    }

    return 0;
}

Output:

Header is NOT NULL! Woohoo!!
OMFG! The file has an ID3v2 tag!!
Tag is NULL!!
hopeseekr commented 8 years ago

The bug is absolutely caused by PR #9. When I reverted to the load_tag of f384f91, it totally worked correctly.

See https://github.com/larsbs/id3v2lib/blob/1815891ae527baf30fa66a2d03729320c00efad0/src/id3v2lib.c

moritzschaefer commented 8 years ago

I'm sorry you are experiencing problems. I used the code after the pull request and didn't experience problems in my application.

hopeseekr commented 8 years ago

Try it now. It's broke.

larsbs commented 8 years ago

Solved after merging your pull request https://github.com/larsbs/id3v2lib/pull/13