How to get ID3 tags from an MP3 file?

2

How to get the arguments that contain a mp3 file using JAVA code, that is, the information such as the year, title, singer, year ... ?

The issue is that what I want is to edit those values or objects ID3 by programming it with java, I know there are programs for it but my idea is to do it with code.

Any idea where to direct my steps? Classes use or recommended external libraries ....

Well many thanks and regards ...

    
asked by Rey Relampago Cortina 01.07.2016 в 20:33
source

2 answers

3

You can use the library jaudiotagger here are some examples .

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

With the object instance Tag you can access properties like

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)

More info here

By the way, I also share a project I did using this library to place images to my Mp3 that did not have, it can serve as a guide and to have a better idea of how to use the library, project in Github . I clarify that the API used to download the images at that time is no longer available:)

    
answered by 01.07.2016 в 21:04
0

This is the program to edit the ID3 tags of an mp3 file.

import java.io.File;

import java.io.IOException;

import org.jaudiotagger.audio.AudioFile;

import org.jaudiotagger.audio.AudioFileIO;

import org.jaudiotagger.audio.exceptions. *;

import org.jaudiotagger.tag. *;

import org.jaudiotagger.tag.id3.ID3v11Tag;

public class edicionTags {

public static void main(String[] args) {

new editmp3 ();

}

}

class editmp3 {

File file = new File ("C: /MancionesMp3/cancion.mp3");

AudioFile audiofile = new AudioFile ();

ID3v11Tag ide = new ID3v11Tag ();

public editarmp3(){

    try {

        audiofile = AudioFileIO.read(archivo);

        Tag tag = audiofile.getTag();                   
        FieldKey[] parametro = {FieldKey.ALBUM,  FieldKey.ARTIST, FieldKey.YEAR, 
                  FieldKey.GENRE, FieldKey.TITLE, FieldKey.TRACK,FieldKey.AMAZON_ID 

              };            
        System.out.println(audiofile.getTag());

        tag.setField(parametro[2], "2020");

        System.out.println(audiofile.getTag());
        try {
            AudioFileIO.write(audiofile);
        } catch (CannotWriteException e) {

            e.printStackTrace();
        }

    } catch (CannotReadException | IOException | TagException | ReadOnlyFileException
            | InvalidAudioFrameException e3) {}

}

}

For the interest of someone in the near future.

Link Library: link

Thank you and good luck greetings ....

    
answered by 03.07.2016 в 13:26