我知道这有点晚了,但以下对我有用(我对其他标签使用相同的框架
public String getmp3TrackTitleTag(File SourceFile)
throws Exception {
String TrackTitle = null;
try {
MP3File musicFile = (MP3File) AudioFileIO.read(SourceFile);
if (musicFile != null && musicFile.hasID3v2Tag()) {
ID3v24Tag id3v24 = (ID3v24Tag) musicFile.getID3v2TagAsv24();
TrackTitle = id3v24.getFirst(ID3v24Frames.FRAME_ID_TITLE);
}
} catch (CannotReadException | IOException | TagException
| ReadOnlyFileException | InvalidAudioFrameException e5) {
throw e5;
}
return TrackTitle;
}
并设置标题
public String setmp3TrackTitleTag(File SourceFile, String strTrackTitle)
throws Exception {
String error = null;
AbstractID3v2Tag v2tag = null;
try {
MP3File musicFile = (MP3File) AudioFileIO.read(SourceFile);
if (musicFile != null && musicFile.hasID3v2Tag()) {
v2tag = musicFile.getID3v2Tag();
try {
v2tag.setField(FieldKey.TITLE, strTrackTitle);
musicFile.setTag(v2tag);
musicFile.commit();
} catch (KeyNotFoundException e) {
e.printStackTrace();
error = e.getMessage();
} catch (FieldDataInvalidException e) {
e.printStackTrace();
error = e.getMessage();
} catch (CannotWriteException e) {
e.printStackTrace();
error = e.getMessage();
}
}
} catch (CannotReadException | IOException | TagException
| ReadOnlyFileException | InvalidAudioFrameException e5) {
throw e5;
}
return error;
}