Read Tag Info from a file

This page refers to all tag formats supported by Jaudioatgger. The stuff you might want to know but you can't change is stored in the AudioHeader class, the meta information that you can change is stored in the Tag interface.


AudioFile f = AudioFileIO.read(testFile);
Tag tag = f.getTag();
AudioHeader = f.getAudioHeader();

AudioHeader includes


f.getAudioHeader().getTrackLength());
f.getAudioHeader().getSampleRateAsNumber());

We try to provide a common api for all tag formats, the FieldKey enum lists all the fields that can be mapped to any of the fully supported formats. A full list of how fields are mapped to the underlying format can be is available in the Tag Mapping Spec We can display the first value of a field using getFirst() ,here are some examples


tag.getFirst(FieldKey.ARTIST);
tag.getFirst(FieldKey.ALBUM);
tag.getFirst(FieldKey.TITLE);
tag.getFirst(FieldKey.COMMENT);
tag.getFirst(FieldKey.YEAR);
tag.getFirst(FieldKey.TRACK);
tag.getFirst(FieldKey.DISC_NO);
tag.getFirst(FieldKey.COMPOSER);
tag.getFirst(FieldKey.ARTIST_SORT)

FieldKey contains full support for all Musicbrainz identifiers, such as


tag.getFirst(FieldKey.MUSICIP_ID);
tag.getFirst(FieldKey.MUSICBRAINZ_TRACK_ID);
tag.getFirst(FieldKey.MUSICBRAINZ_ARTISTID);
tag.getFirst(FieldKey.MUSICBRAINZ_RELEASEARTISTID);
tag.getFirst(FieldKey.MUSICBRAINZ_RELEASEID);	

You do not have to worry about complications with different formats, for example we have two fields TRACK and TRACK_TOTAL for storing the track number on a release, and the total tracks on a release. MP3 and MP4 formats stored both these values within a single field whereas WMA, Flac and OggVorbis store them as two seperate fields, jaudiotagger takes care of this behind the scenes and you can just treat as two seperate fields whatever format you are reading or writing to.

If the format supports supports multiple items with the same id you can retrieve all items with a particular id using


List list = tag.get(FieldKey.ARTIST);
for(TagField field:list)
{
	field);
}	

To retrieve all items in a tag use


Iterator iterator = tag.getFields();
while(iterator.hasNext())
{
    iterator.next());
}	

The examples above assume textual data, but what about binary data. You can retrieve the complete tag field instead of just a String representation of its value by using getFirstField()


TagField binaryField = tag.getFirstField(FieldKey.COVER_ART));