开发者

how do I read frames of id3v2?

I'm trying to read id3 frames and my problem is I can't get full title. When title of mp3 is long, my result is string without end and without first 9 characters. If title of the song is short my result is title without first 9 characters.

struct ID3V2frame
{
    char header[4];
    char *id3frame[readBytes开发者_运维技巧];
    int sizze[4];
}frame;

fseek(file,10,SEEK_SET); // skip id3 header

fread(&frame.header,sizeof(frame),1,file);


readBytes = ((frame.sizze[0] & 127) << 21) |
((frame.sizze[1] & 127) << 14) |
((frame.sizze[2] & 127) << 7)  |
(frame.sizze[3] & 127); 

fread(&frame.id3frame,sizeof(frame),1,file);
if(strncmp(frame.header,"TIT2", 4) == 0)
    printf("%s",frame.id3frame);


I know there is something wrong, because sizeof(struct ID3V2frame) will return:

sizeof(char[4]) + sizeof(char pointer) + sizeof(int[4])

Note, that the struct has a POINTER to a char, and a pointer is probably 4 bytes in your system. So you are fread()'ing the wrong size and in the wrong way.

I don't know about ID3 but somewhere in the header must be the size of this string.

Edit: Reading the doc

ID3v2 frame overview

As the tag consists of a tag header and a tag body with one or more frames, all the frames consists of a frame header followed by one or more fields containing the actual information. The layout of the frame header:

Frame ID $xx xx xx xx (four characters)

Size $xx xx xx xx

Flags $xx xx

The frame ID is followed by a size descriptor, making a total header size of ten bytes in every frame. The size is calculated as frame size excluding frame header (frame size - 10).

Your frame struct is wrong.

After you fixed your struct and have the proper total size, you can fread() size-10 bytes to get the contents of the frame.

Be careful because you need to check the Frame ID to see if it's the Title's file name frame, since the spec says they can be in ANY order.

Please, refer to the docs. ID3v2 seem well documented. I was able to get all that info in 5mins.

http://www.id3.org/id3v2.3.0

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜