我正在尝试使用 jaudiotagger 更改音频文件的专辑封面,但它不起作用。关于这个主题有很多问题,但没有一个能满足我的要求。其他字段,如艺术家、音频名称、专辑等已成功更新,但专辑插图保持不变。
我用来更改艺术品的代码:
public void changeAlbumArt(Uri data) {
Artwork cover = null;
try {
AudioFile f = null;
try {
f = AudioFileIO.read(new File(storageUtil.loadAudio().get(storageUtil.loadAudioIndex()).getData()));
} catch (CannotReadException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (TagException e) {
e.printStackTrace();
} catch (ReadOnlyFileException e) {
e.printStackTrace();
} catch (InvalidAudioFrameException e) {
e.printStackTrace();
}
Tag tag = null;
if (f != null) {
tag = f.getTag();
}
try {
if(tag!=null) {
cover = ArtworkFactory.createArtworkFromFile(new File(data.getPath()));
tag.deleteArtworkField();
tag.setField(cover);
}
} catch (FieldDataInvalidException e) {
e.printStackTrace();
}
try {
if (f != null) {
f.commit();
}
} catch (CannotWriteException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
File file = new File(storageUtil.loadAudio().get(storageUtil.loadAudioIndex()).getData());
Uri uri = Uri.fromFile(file);
Intent scanFileIntent = new Intent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
sendBroadcast(scanFileIntent);
}