需要的库下载

audio.jar
jaudiotagger-2.2.6-SNAPSHOT.jar
jl1.0.1.jar
jmf.jar
sound.jar

读属性
MP3File mp3File = (MP3File) AudioFileIO.read(new File("/Users/wujieyuan/Music/QQ音乐/王力宏-大城小爱.mp3"));
MP3AudioHeader audioHeader = (MP3AudioHeader) mp3File.getAudioHeader();

String songname = mp3File.getID3v2Tag().frameMap.get("TIT2").toString();//歌名
String artist = mp3File.getID3v2Tag().frameMap.get("TPE1").toString();//歌手
String album = mp3File.getID3v2Tag().frameMap.get("TALB").toString();//专辑
int duration = audioHeader.getTrackLength();//时长

Path flacPath = Paths.get("/Volumes/music/洛雪音乐助手/东西 - 林俊呈.flac");
FlacInfoReader reader=new FlacInfoReader();
FlacAudioHeader flacAudioHeader = reader.read(flacPath);
System.out.println(flacAudioHeader.toString());

FlacTagReader flacTagReader=new FlacTagReader();
FlacTag flacTag = flacTagReader.read(flacPath);
System.out.println(flacTag.toString())
写属性
File dir = new File("/Volumes/music/洛雪音乐助手");
for (File file : dir.listFiles()) {
    if (file.getName().endsWith(".flac")) {
        String[] strings = file.getName().replace(" ", "").split("-");
        String musicName = strings[0];
        String userName = strings[1].replace(".flac", "");

        Path flacPath = Paths.get(file.getPath());
        FlacTagReader flacTagReader = new FlacTagReader();
        FlacTag flacTag = flacTagReader.read(flacPath);

        String ARTIST = null;
        VorbisCommentTag vorbisCommentTag = flacTag.getVorbisCommentTag();
        Iterator<TagField> fields = vorbisCommentTag.getFields();
        while (fields.hasNext()) {
            TagField field = (TagField) fields.next();
            if ("ARTIST".equals(field.getId())) {
                ARTIST = field.toString();
                break;
            }
        }
        if(ARTIST!=null&&"kuwo".equals(ARTIST)){
            FlacTagWriter flacTagWriter=new FlacTagWriter();
            flacTag.setField("ARTIST",userName);
            flacTag.setField("TITLE",musicName);
            flacTagWriter.write(flacTag,flacPath);
            System.out.println("编辑文件:"+file.getName());
        }
    }
最后修改日期:2019年11月29日

作者

留言

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。