I'm trying to change the album art of an audio file using jaudiotagger but it is not working. There are a lot of question regarding this topic but none of them fulfilled my requirements. Other fields such as artist,audio name, album etc are updated successfully but the album artwork remains the same.
The code I'm using to change the artwork:
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);
}