JAudioTagger does not change album art on Android

Issue #177 closed
Dhyan Chand created an issue

Since I have tried so many permutations and combinations and nothing is working I am not sure if JAudioTagger even supports it?

I am trying the following code in order to change album art of mp3s in my android app

final AudioFile f;
        try {
            TagOptionSingleton.getInstance().setAndroid(true);
            f = AudioFileIO.read(new File(name));
            final Tag tag = f.getTag();
            tag.setField(FieldKey.TITLE, title);
            tag.setField(FieldKey.ARTIST,name);
            tag.setField(FieldKey.ALBUM, album);
            if (path!=null) {
                Artwork cover = ArtworkFactory.createArtworkFromFile(new File(path));
                tag.deleteArtworkField();
                tag.setField(cover);
            }
            f.commit();
            Toast.makeText(context, "Updated", Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            e.printStackTrace();
        }

The texts changes perfectly but the artwork does not, it stays the same. Few guys have asked questions about it on StackOverflow but no answers there. Is it even possible to do this on Android using JAudiotagger? Thanks !!

Comments (4)

  1. IJabz repo owner

    Sorry I dont know since I've never used jaudiotagger on Androi but I dont see why it shoudnt work, perhaps you just have to update a cache. Try copying the file onto your computer and seeing if the artwork is visible then, if so its just an issue with your Android config.

  2. Denimsun Basumatary

    Updating album art works on android using JaudioTagger. Can you please post the exception?

  3. Theo Klink

    I use jaudiotagger-2.2.4-SNAPSHOT.jar (having all sorts of trouble with libs/jaudiotagger-2.2.6-SNAPSHOT.jar) The folowing code works without issues:

                          public String setMp3AlbumArt(File SourceFile, byte[] bytes)
                throws Exception {
            String error = null;
            try {
                AudioFile musicFile  = AudioFileIO.read(SourceFile);
                Tag tag = musicFile.getTag();
    
                if(tag!=null) {
                    Artwork artwork = ArtworkFactory.createArtworkFromFile(SourceFile);
                    artwork.setBinaryData(bytes);
                    tag.deleteArtworkField();
                    tag.setField(artwork);
                    musicFile.setTag(tag);
                    musicFile.commit();
                }
    
            } catch (CannotReadException | IOException | TagException
                    | ReadOnlyFileException | InvalidAudioFrameException e) {
                error = e.getMessage();
            }
            return error;
        }
    

    Note bytes is obtained as follows:

        Uri imageUri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, String.valueOf(id));
        Bitmap scaledbmp = decodeSampledBitmapFromResource(imageUri, 300, 300);
        if (scaledbmp != null) {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            scaledbmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] byteArray = stream.toByteArray();
    

    ....

  4. Log in to comment