1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
FILE *fichierMP3;
fpos_t pos;
unsigned char buf[10]; //Tampon
unsigned char a,b,c,d;
char buf2[50]; //Tampon
char buf3[50]; //Tampon
char TAG[10]; //contient le tag en cour
int i,j; //compte les blancs
bool fin=false; //fin de boucle
bool tagfound;
unsigned long size; //taille du tag globale
unsigned long tagsize;//Taille du tag en question
OpenDialog1->Execute();
//Tentative d'ouverture du fichier en lecture seule
if ((fichierMP3=fopen(OpenDialog1->FileName.c_str(),"rb"))==NULL)
//le fichier n'a pas pu etre ouvert
Application->MessageBox("Le fichier n'a pa pus être ouvert","Erreur",MB_ICONEXCLAMATION);
else
{//On se place en début de fichier
fseek(fichierMP3,0,SEEK_SET);
//Lecture de la présence ou nom d'un tag ID3
fread(buf,3,1,fichierMP3);
//Si pas d'ID3 on affiche une boite de dialoque
if (strcmp(buf,"ID3"))
Application->MessageBox("Le fichier indiquer ne contient aucune information","Erreur",MB_ICONEXCLAMATION);
else
{//lecture de la taille du TAG
fseek(fichierMP3,6L,SEEK_SET);
fread(buf,4,1,fichierMP3);
size=((((unsigned short)buf[0])<<21)|(((unsigned short)buf[1])<<14 )|(((unsigned short)buf[2])<<7 )|((unsigned short)(buf[3])));
//on lit les éléments jusqu'a la fin du tag
pos=0;
while (pos<size)
{ tagfound=true;
//Lecture du nom du champ
fread(TAG,0x4, 1, fichierMP3);//On lit le nom du tag
TAG[4]=NULL;
// lire la largeur du champs
fread(buf,0x6L, 1, fichierMP3);
a=buf[0];
b=buf[1];
c=buf[2];
d=buf[3];
tagsize=a << 21 |b << 14 | c << 7 | d;
//On passe les drapeaux
//On lit le contenu du tag
fread(buf2,tagsize,1,fichierMP3);
//Supprimer les caratères en trop au début s'il y'en a
if (tagfound)
{i=0;
while (buf2[i]==0x00)
{for (j=0;j<tagsize;j++)
buf2[j]=buf2[j+1];
i++;
}
buf2[tagsize-1]=0;
}
//Affiche l'information correspondante
if (!strcmp(TAG, "TPE1")) //Si tag artiste
Lb_Artiste->Text=buf2;
if (!strcmp(TAG,"TYER")) //Si tag année
Lb_Annee->Text=buf2;
if (!strcmp(TAG, "TALB")) //Si tag album
Lb_Album->Text=buf2;
if (!strcmp(TAG, "TIT2")) //...
Lb_Titre->Text=buf2;
if (!strcmp(TAG, "TCON"))
ComboBox1->Text=buf2;
// regarder ou nous somme dans le fichier
fgetpos(fichierMP3, &pos);
}
}
fclose(fichierMP3);
} |
Partager