I need to read mp3 tags. After a little search here, nothing especific found, then, post. The program is running, but the output has something wrong. Maybe some string length.
Here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{
char tag[3];
char title[30];
char artist[30];
char album[30];
char year[4];
char comment[30];
unsigned char genre;
}mp3Tags;
int main()
{
mp3Tags currentTags;
char fileName[101];
FILE *mp3File;
printf("MP3 file name: "); fgets(nameFile, 100, stdin);
fileName[strlen(fileName)-1] = '\0';
// Open mp3 file
mp3File = fopen(fileName, "rb");
if (mp3File == NULL)
{
printf("\nUnable to open mp3 file!\n");
exit(0);
}
// Puts the pointer to the end of file
fseek(mp3File, 0, SEEK_END);
// Get position
long pos = ftell(mp3File);
// Puts the pointer at the tag's read place
fseek(mp3File, (pos - sizeof(mp3Tags)), SEEK_SET);
// Read mp3 tags
if(fread(¤tTags, sizeof(mp3Tags), 1, mp3File) != 1)
{
printf("\nUnable to read tags!\n");
exit(0);
}
printf("\n\nTags:\n");
printf("TAG: %s\n", currentTags.tag);
printf("Title: %s\n", currentTags.title);
printf("Artist: %s\n", currentTags.artist);
printf("Album: %s\n", currentTags.album);
printf("Year: %s\n", currentTags.year);
printf("Comment: %s\n", currentTags.comment);
printf("Genre: %c\n", currentTags.genre);
printf("End! Closing mp3 file!\n");
// Close mp3 file
fclose(mp3File);
return(0);
}
Ouput:
MP3 file name: Mozart.mp3 Tags: TAG: TAGThe Miskolc Experience - 04 - Title: The Miskolc Experience - 04 - Artist: Therion Album: The Miskolc Experience Year: 2009 Comment: Genre: ? End! Closing mp3 file!
Thanks for the help.
PS: Linux here.

New Topic/Question
Reply




MultiQuote






|