Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the title property of mp3 file using java api

Tags:

java

I have more than 1000 mp3 files in one of my folder "D:\songs\Innisai Malai". Now, I want to update all file's title property to its file Name and all file's album name to Innisai Malai.

How to do it using java. Is there any API available to update the title to its file name for all the files at a time without impacting the file's sound quality.

like image 706
Karthick Avatar asked Sep 28 '15 10:09

Karthick


People also ask

Can you play mp3 in Java?

It turned out that Java 7 has support for mp3 files: String bip = "example. mp3"; Media hit = new Media(bip); MediaPlayer mediaPlayer = new MediaPlayer(hit); mediaPlayer. play();

What is mp3 metadata?

Metadata, also referred to as ID3 tag for mp3 files, is the identifying information associated with your song, such as the. composers. performers. song title. title of the album on which it was released.


2 Answers

https://github.com/mpatric/mp3agic

this library is available on GitHub. using it you can open a mp3 file

Mp3File mp3file = new Mp3File("xxx.mp3");

fetch its ID3v1 tag

ID3v1 id3v1Tag = mp3file.getId3v1Tag();

and modify using

setTitle(String)

like image 127
Abhijeet Kale Avatar answered Sep 30 '22 05:09

Abhijeet Kale


You need to edit ID3 tag. There are several libraries, which can do it, for example: mp3agic or javamusictag

Here is an official example for mp3agic library:

Mp3File mp3file = new Mp3File("SomeMp3File.mp3");
ID3v1 id3v1Tag;
if (mp3file.hasId3v1Tag()) {
  id3v1Tag =  mp3file.getId3v1Tag();
} else {
  // mp3 does not have an ID3v1 tag, let's create one..
  id3v1Tag = new ID3v1Tag();
  mp3file.setId3v1Tag(id3v1Tag);
}
id3v1Tag.setTrack("5");
id3v1Tag.setArtist("An Artist");
id3v1Tag.setTitle("The Title");
id3v1Tag.setAlbum("The Album");
id3v1Tag.setYear("2001");
id3v1Tag.setGenre(12);
id3v1Tag.setComment("Some comment");
mp3file.save("MyMp3File.mp3");
like image 32
Stanislav Avatar answered Sep 30 '22 07:09

Stanislav