Handling the ID3v1 tag
Leave feedback
ID3v1 is a metadata tag that is usually used with MP3 audio files. The whole tag occupies 128 bytes and allows adding metadata properties such as title, artist, album, track number, etc.The ID3v1 standard was introduced in 1996 but it’s still widely supported by various audio players and decoders. To get more information about ID3v1 tags please visit http://id3.org/ID3v1.
The following steps show how to read the ID3v1 tag in an MP3 file.
- Load an MP3 file
- Extract the root metadata package
- Get the ID3v1 tag by using the Mp3RootPackage.getID3V1 method
- If the ID3v1 tag is not null then check for all of its metadata properties
advanced_usage.managing_metadata_for_specific_formats.
try (Metadata metadata = new Metadata(Constants.MP3WithID3V1)) {
MP3RootPackage root = metadata.getRootPackageGeneric();
if (root.getID3V1() != null) {
System.out.println(root.getID3V1().getAlbum());
System.out.println(root.getID3V1().getArtist());
System.out.println(root.getID3V1().getTitle());
System.out.println(root.getID3V1().getVersion());
System.out.println(root.getID3V1().getComment());
// ...
}
}
The following are the steps to update the ID3v1 tag in an MP3 file.
- Load an MP3 file
- Extract the root metadata package
- Create the ID3v1 tag if it’s missing
- Update ID3v1 fields using the Mp3RootPackage.getID3V1 method
- Save the changes
The following code snippet shows how to update the ID3v1 tag in an MP3 file.
advanced_usage.managing_metadata_for_specific_formats.
try (Metadata metadata = new Metadata(Constants.MP3WithID3V1)) {
MP3RootPackage root = metadata.getRootPackageGeneric();
if (root.getID3V1() == null) {
root.setID3V1(new ID3V1Tag());
}
root.getID3V1().setAlbum("test album");
root.getID3V1().setArtist("test artist");
root.getID3V1().setTitle("test title");
root.getID3V1().setComment("test comment");
root.getID3V1().setYear("2019");
// ...
metadata.save(Constants.OutputMp3);
}
To remove the ID3v1 tag from an MP3 audio just pass null to the Mp3RootPackage.setID3V1 method as a parameter. The code sample below shows how to remove the ID3v1 tag from an MP3 file.
advanced_usage.managing_metadata_for_specific_formats.
try (Metadata metadata = new Metadata(Constants.MP3WithID3V1)) {
MP3RootPackage root = metadata.getRootPackageGeneric();
root.setID3V1(null);
metadata.save(Constants.OutputMp3);
}
You may easily run the code above and see the feature in action in our GitHub examples:
Along with full featured Java library we provide simple, but powerful free Apps.
You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.