Archived

This topic is now archived and is closed to further replies.

amemorex

id3 reader - please help!

Recommended Posts

i''m trying to make a simple ID3 reader in C++, but it''s um..not working heh. someone please tell me what i''m doing wrong here
  
#include <iostream.h>
#include <stdio.h>

struct ID3 {
	char tag[3];
	char title[30];
	char artist[30];
	char album[30];
	char year[4];
	char comment[30];
	char genre[1];
};

void main() {
        int file_size;
	ID3 mp3;
	FILE *in;
	in = fopen("c:/audio/whatever.mp3", "rb");
        file_size = 49251; // <-- this is just temporary because i already know the size in bytes of the mp3

	fseek(in, (file_size - 128), SEEK_SET);
	fread(&mp3, 1, 128, in);

	cout << mp3.artist;

	fclose(in);
}
  
anyway, it''s just returning garbaged letters, you know what im talking about. the id3 is always at the last 128 bytes of the file, so i''m seeked to the last 128 bytes (filesize - 128), and tried to simply read in all 128 bytes into the structure it''s not working though..what am i doing wrong??

Share this post


Link to post
Share on other sites
What exactly isn''t working?

I really would try and avoid using hardcoded values, even when doing testing such as this. Alignment issues can prove this point fatally.

A File size isn''t hard to get, just

fseek(in, SEEK_END);
file_size = ftell(in);
fseek(in, SEEK_SET);

and you may want to fread() the sizeof(struct ID3).

But thats all tertiary really - I''d like to know the specifics of ''not working'' (getting partial name, no name, no file open?)

-Mezz

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by amemorex
i''m trying to make a simple ID3 reader in C++, but it''s um..not working heh. someone please tell me what i''m doing wrong here


    
#include <iostream.h>
#include <stdio.h>

struct ID3 {
char tag[3];
char title[30];
char artist[30];
char album[30];
char year[4];
char comment[30];
char genre[1];
};

void main() {
int file_size;
ID3 mp3;
FILE *in;
in = fopen("c:/audio/whatever.mp3", "rb");
file_size = 49251; // <-- this is just temporary because i already know the size in bytes of the mp3

fseek(in, (file_size - 128), SEEK_SET);
fread(&mp3, 1, 128, in);

cout << mp3.artist;

fclose(in);
}


anyway, it''s just returning garbaged letters, you know what im talking about.

the id3 is always at the last 128 bytes of the file, so i''m seeked to the last 128 bytes (filesize - 128), and tried to simply read in all 128 bytes into the structure

it''s not working though..what am i doing wrong??


struct ID3 {
char tag[3];
char title[30];
char artist[30];
char album[30];
char year[4];
char comment[30];
char genre[1];
};

void main() {
int file_size;
ID3 mp3;
FILE *in;
in = fopen("c:/audio/whatever.mp3", "rb";
fseek(in, -128, SEEK_END);
fread(&mp3, 1, 128, in);
cout << mp3.artist;

fclose(in);
}
[/source]
This should work

Share this post


Link to post
Share on other sites