Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read ID3 Tags of an MP3 file

I am trying to read ID3 from a mp3 file thats locally stored in the SD card.

I want to basically fetch

  1. Title
  2. Artist
  3. Album
  4. Track Length
  5. Album Art
like image 430
Harsha M V Avatar asked Jun 10 '11 12:06

Harsha M V


3 Answers

Check the MP3 file format. Basically, you have to read the last 128 bytes of the file; if the first 3 bytes are "TAG", carry on and read the fields you need; if not, the file doesn't have the info attached.

like image 176
Gabriel Negut Avatar answered Oct 11 '22 23:10

Gabriel Negut


if the last 128 byte begins with the token "TAG" the file has an ID3v1 (or ID3v1.1) tag. ID3v2.3 tags are located in the beginning of the file (suitable for streaming) indicated by the token "id3". I believe ID3v2.4 is indicated by "3DE", but i'm not sure...

like image 41
user2306609 Avatar answered Oct 11 '22 23:10

user2306609


You can get all of this using MediaMetadataRetriever

MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(filePath);

String albumName =
     mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
like image 39
Reno Avatar answered Oct 12 '22 01:10

Reno