Jaudiotagger ID3 TAG for android - can set artwork but cannot set other fields

拜拜、爱过 提交于 2019-12-21 06:03:57

问题


I'm relatively new to Java programming. Here i'm trying to use Jaudiotagger library for altering/creating new ID3 tag for mp3s without one in one of my android project. However, I really cannot set to made the library work correctly. That is, For mp3s with some ID3 tag already set, I can successfully write and change the metadata without any problems. But for those mp3s who has no ID3 tag set (blank), I can only manage to set the album cover artwork and other fields like artist, title, album cover, etc remain blank as before.

Here is a snippet of my code -

import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.Tag;
import org.jaudiotagger.tag.TagOptionSingleton;
import org.jaudiotagger.tag.id3.ID3v23Tag;
import org.jaudiotagger.tag.images.Artwork;
import org.jaudiotagger.tag.images.ArtworkFactory;

try{
    TagOptionSingleton.getInstance().setAndroid(true);
    AudioFile f =AudioFileIO.read(file_path_to_mp3);
    f.setTag(new ID3v23Tag());
    Tag tag=f.getTag();
    tag.setField(FieldKey.ARTIST,artist);
    tag.setField(FieldKey.ALBUM,album);
    Artwork cover=ArtworkFactory.createArtworkFromFile(cover_file);
    tag.setField(cover);
    f.commit();
}catch (Exception e){
    e.printStackTrace();
}

I can run the program without getting any error and exception thrown. Just that the matadata tag like title, artist, album etc wont set though the artwork can be set successfully. Thanks for any help!


回答1:


I write some code to help you change the data of the mp3 file

    TagOptionSingleton.getInstance().setAndroid(true);

    File mp3File = new File(mp3Song);

    AudioFile audioFile = AudioFileIO.read(mp3File);

    audioFile.setTag(new ID3v23Tag());


    Tag newTag=    audioFile.getTag();

    if (album != null) {
        newTag.setField(ALBUM, album);
    }
    if (artist != null) {
        newTag.setField(ARTIST, artist);
    }

    if (trackName != null) {
        Log.d("ALBUM TITLE",trackName);

        newTag.setField(TITLE, trackName);
    }


    if (imageAlbum != null) {
        Log.d("ALBUM COVER",imageAlbum);

        File fileCover = new File(imageAlbum);
        if (!fileCover.exists()){

            Log.d("ALBUM ","DOESNT EXIST");

        }


        Artwork artwork = Artwork.createArtworkFromFile(fileCover);
        newTag.addField(artwork);
        newTag.setField(artwork);

    }
    audioFile.commit();de here


来源:https://stackoverflow.com/questions/23530339/jaudiotagger-id3-tag-for-android-can-set-artwork-but-cannot-set-other-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!