954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Reading ID3v2.x

Hello

I'm trying to read the ID3 tag from a file. For now, I print out the string that I've read and I can see the title, year and so on but in the specs it says that the first 7 bytes contain ID3, the version, some flags and the size of the tag. But I can only see the ID3-string. This is some of the output:
ID3 C @TRCK 4/16TIT2PossibilityTP

It doesn't get pasted here but there are symbols between the ID3, C and the @ and in other places. ( I had to replace them with spaces but actually there are like 5 symbols in between) So the bytes I need are being read but not outputted. I guess they are the C and @ but I need them in integer/double format. It should be 1098058bytes for this file but it is variable for each file.

This is my code:

std::strings = "04 Possibility.mp3";
    int tagsize = 50;

    char buffer[tagsize];

    std::ifstream mp3File(s.c_str(),std::ios::binary);
    mp3File.getline(buffer, tagsize);

    std::string outp("");
    for (int i = 0; i <= tagsize; ++i){
        outp.push_back(buffer[i]);
    }
    std::cout << outp << std::endl;


The tagsize is just for debugging purposes, its size is 1098058bytes which crashes the output.

Anyone got any ideas on how to get the 1098058 from the file header?

Thanks, Jasper

Japus
Light Poster
28 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 
for (int i = 0; i <= tagsize; ++i)

This goes one beyond the array bounds.

int tagsize = 50;

    char buffer[tagsize];

Since tagsize is not const, it would seem that you are using a nonstandard extension. Be aware of that.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

Ok, changed that but what is a nonstandard extention?
Still no difference in the output though.

Japus
Light Poster
28 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

http://en.wikipedia.org/wiki/ID3
They're not all-text.
They're not always at the beginning,
They're not always present.
They're not always ASCII.

You can't just open the file and read a string, and hope it all works.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You