Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the Java MP3 ID3 Tag Library to retrieve album artwork

Tags:

java

id3v2

I'm making an mp3 player. I'm using the Java mp3 id3 tag library. I understand that album artwork is encoded as a ID3v2 tag.

I can access the ID3v2 tag of a mp3 file however I cannot get the artwork! None of the methods in the AbstractID3v2 class, in the API seem to retrieve a picture.

How does one use this library?

like image 701
Adeeb Avatar asked Feb 06 '13 12:02

Adeeb


2 Answers

I ended up using another library, I used mp3agic

It's a great library which is easy to use. Here's sample code I used to get the album artwork

Mp3File song = new Mp3File(filename);
if (song.hasId3v2Tag()){
     ID3v2 id3v2tag = song.getId3v2Tag();
     byte[] imageData = id3v2tag.getAlbumImage();
     //converting the bytes to an image
     BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageData));
}
like image 55
Adeeb Avatar answered Nov 17 '22 01:11

Adeeb


There's also Jaudiotagger which can read/write Mp3, Mp4 (Mp4 audio, M4a and M4p audio) Ogg Vorbis, Flac and Wma + some others (album art too).

MP3File f = (Mp3File)AudioFileIO.read(testFile);
List<Artwork> artworkList;
if (f.hasID3v1Tag()) {
    ID3v1Tag v1tag = f.getID3v1Tag();
    artworkList = (List<Artwork>) v1tag.getArtworkList();
    /* ... */
}
like image 3
user667 Avatar answered Nov 17 '22 01:11

user667