943,148 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 826
  • C++ RSS
Jan 18th, 2010
0

Reading ID3v2.x

Expand Post »
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:
C++ Syntax (Toggle Plain Text)
  1. std::strings = "04 Possibility.mp3";
  2. int tagsize = 50;
  3.  
  4. char buffer[tagsize];
  5.  
  6. std::ifstream mp3File(s.c_str(),std::ios::binary);
  7. mp3File.getline(buffer, tagsize);
  8.  
  9. std::string outp("");
  10. for (int i = 0; i <= tagsize; ++i){
  11. outp.push_back(buffer[i]);
  12. }
  13. 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Japus is offline Offline
28 posts
since Nov 2009
Jan 18th, 2010
0
Re: Reading ID3v2.x
for (int i = 0; i <= tagsize; ++i)
This goes one beyond the array bounds.
C++ Syntax (Toggle Plain Text)
  1. int tagsize = 50;
  2.  
  3. char buffer[tagsize];
Since tagsize is not const, it would seem that you are using a nonstandard extension. Be aware of that.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jan 18th, 2010
0
Re: Reading ID3v2.x
Ok, changed that but what is a nonstandard extention?
Still no difference in the output though.
Reputation Points: 10
Solved Threads: 0
Light Poster
Japus is offline Offline
28 posts
since Nov 2009
Jan 18th, 2010
1
Re: Reading ID3v2.x
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.
Team Colleague
Reputation Points: 5862
Solved Threads: 949
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Problem initializing a dynamic array
Next Thread in C++ Forum Timeline: sin, cos, tan





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC