Jaudiotagger ID3标签Android的 - 可设置的艺术作品,但不能设置其他领域 [英] Jaudiotagger ID3 TAG for android - can set artwork but cannot set other fields

查看:362
本文介绍了Jaudiotagger ID3标签Android的 - 可设置的艺术作品,但不能设置其他领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是比较新的Java编程。在这里,我尝试使用Jaudiotagger库改变/无一在我的Andr​​oid项目之一,创造了新的MP3 ID3标签。不过,我真的不能设置做出的库工作正常。那是,
对于一些ID3标签的MP3已经设置,我可以成功编写和修改元数据没有任何问题。但谁没有ID3标签组(空白)的MP3音乐,我只能管理设置专辑封面图案等领域像艺术家,标题,专辑封面等保持空白和以前一样。

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.

下面是我的code的片段 -

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();
}

我没有得到抛出的任何错误和异常运行程序。只是,如标题,艺术家,专辑等的matadata标签惯于设置虽然艺术品能够建立成功。
感谢您的帮助!

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!

推荐答案

我写了一些code帮你换的MP3文件的数据

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

这篇关于Jaudiotagger ID3标签Android的 - 可设置的艺术作品,但不能设置其他领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆