How do you edit MP3 files in Java (ID3)?

前端 未结 5 1117
夕颜
夕颜 2021-01-05 07:42

Lately, I\'ve been trying to write a program that can change the ID3 tags of an mp3 file. I managed to write code to get those tags quite easily, but I have no idea how to w

相关标签:
5条回答
  • 2021-01-05 07:56

    please check this.

    https://www.rgagnon.com/javadetails/java-process-mp3-tags.html

    Jaudiotagger (bitbucket repo)is the Audio Tagging library for tagging data in Audio files. It currently fully supports Mp3, Mp4 (Mp4 audio, M4a and M4p audio) Ogg Vorbis, Flac and Wma, there is limited support for Wav and Real formats.

    0 讨论(0)
  • 2021-01-05 08:12

    And for anyone stumbling onto this all these years on, mp3agic might be handy.

    0 讨论(0)
  • 2021-01-05 08:12

    Processing has ways of manipulating audio, video, and even 3d (and of course normal images)

    0 讨论(0)
  • 2021-01-05 08:13

    This library:

    http://javamusictag.sourceforge.net/

    provides a means of reading and writing id3 tags.

    0 讨论(0)
  • 2021-01-05 08:19

    You should have a look at the library jAudioTagger. Below is an example that writes a custom tag (TXXX) to an audio file:

    /**
     * This will write a custom ID3 tag (TXXX).
     * This works only with MP3 files (Flac with ID3-Tag not tested).
     * @param description The description of the custom tag i.e. "catalognr"
     * There can only be one custom TXXX tag with that description in one MP3 file
     * @param text The actual text to be written into the new tag field
     * @return True if the tag has been properly written, false otherwise
     */
    
    public boolean setCustomTag(AudioFile audioFile, String description, String text){
        FrameBodyTXXX txxxBody = new FrameBodyTXXX();
        txxxBody.setDescription(description);
        txxxBody.setText(text);
    
        // Get the tag from the audio file
        // If there is no ID3Tag create an ID3v2.3 tag
        Tag tag = audioFile.getTagOrCreateAndSetDefault();
        // If there is only a ID3v1 tag, copy data into new ID3v2.3 tag
        if(!(tag instanceof ID3v23Tag || tag instanceof ID3v24Tag)){
            Tag newTagV23 = null;
            if(tag instanceof ID3v1Tag){
                newTagV23 = new ID3v23Tag((ID3v1Tag)audioFile.getTag()); // Copy old tag data               
            }
            if(tag instanceof ID3v22Tag){
                newTagV23 = new ID3v23Tag((ID3v11Tag)audioFile.getTag()); // Copy old tag data              
            }           
            audioFile.setTag(newTagV23);
        }
    
        AbstractID3v2Frame frame = null;
        if(tag instanceof ID3v23Tag){
            frame = new ID3v23Frame("TXXX");
        }
        else if(tag instanceof ID3v24Tag){
            frame = new ID3v24Frame("TXXX");
        }
    
        frame.setBody(txxxBody);
    
        try {
            tag.addField(frame);
        } catch (FieldDataInvalidException e) {
            e.printStackTrace();
            return false;
        }
    
        try {
            audioFile.commit();
        } catch (CannotWriteException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
    
    0 讨论(0)
提交回复
热议问题