Сначала вопрос: в MP3 дополнительная информация хранится двумя способами - в тэгах ID3v1 и ID3v2. Получение данных из какого тэга вас интересует ? Для версии 1 (и 1.1) примерно так:
Код | BOOL bResult = FALSE;
CFile fHandle; bIsID3v1Found = FALSE; bIsID3v2Found = FALSE; bIsID3v1_1 = FALSE;
// открываем файл, если неудачно - выходим с ошибкой if(!fHandle.Open(strFileName, CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary)) return FALSE; else { int iBytesRead = 0; char *pBuf[30]; CString strTmp = "";
// ищем тэг ID3v1 fHandle.Seek((fHandle.GetLength() - 128), 0); //Считываем первые 3 bytes и проверяем на соответствие "TAG" iBytesRead = fHandle.Read(pBuf, 3); strTmp.Format("%s", pBuf); strTmp.Insert(iBytesRead, '\0'); strTmp.MakeUpper(); if(strTmp == "TAG") { // значит есть ID3v1 тэг bIsID3v1Found = TRUE;
// проверяем версию тэга char *pVerBuf[1]; fHandle.Seek((fHandle.GetLength() - 3), 0); iBytesRead = fHandle.Read(pVerBuf, 1); strTmp.Format("%s", pVerBuf); if(strTmp == "\0") { // значит версия 1.1 bIsID3v1_1 = TRUE; }
// считываем данные тэга fHandle.Seek((fHandle.GetLength() - 125), 0);
//Read the next 30 bytes, which is the TrackName. iBytesRead = fHandle.Read(pBuf, 30); strTmp.Format("%s", pBuf); strTitle = strTmp.Left(iBytesRead);
//The next 30 are the Artist. iBytesRead = fHandle.Read(pBuf, 30); strTmp.Format("%s", pBuf); strArtist = strTmp.Left(iBytesRead);
//The next 30 are the Album Name. iBytesRead = fHandle.Read(pBuf, 30); strTmp.Format("%s", pBuf); strAlbum = strTmp.Left(iBytesRead);
//The next 4 bytes are Year. iBytesRead = fHandle.Read(pBuf, 4); strTmp.Format("%s", pBuf); strYear = strTmp.Left(iBytesRead);
//The next 28-30 are comments. if(bIsID3v1_1 == TRUE) { iBytesRead = fHandle.Read(pBuf, 28); strTmp.Format("%s", pBuf); strComment = strTmp.Left(iBytesRead); } else { iBytesRead = fHandle.Read(pBuf, 30); strTmp.Format("%s", pBuf); strComment = strTmp.Left(iBytesRead); }
bResult = TRUE; }
// закрываем fHandle.Close(); }
|
для версии 2 не знаю (хотя хотелось-бы какой-нить примерчик кода). |