Can't get track ID3 tags using jaudiotagger

530 Views Asked by At

I'm trying to read ID3 tags from a .m4a file using the jaudiotagger Library with the following code

try {
        File file = new File(TrackPath);
        AudioFile f = AudioFileIO.read(file);
        Tag tag = f.getTag();

        audioAlbum.setText(tag.getFirst(FieldKey.ARTIST));
    }catch(Exception e) {
        e.printStackTrace();
    };

But this returns the same error:

java.lang.NoSuchMethodError: No virtual method toPath()Ljava/nio/file/Path; in class Ljava/io/File;

The string TrackPath contains the "MediaStore.Audio.Media.DATA" of the .m4a file

I have never worked with exceptions before, so I think the problem is somewhere in there.

2

There are 2 best solutions below

1
Miguel On BEST ANSWER

I found the problem, the original Library is not working for Android due to some java versions problems. So ended up using this library instead https://github.com/hexise/jaudiotagger-android

0
Prosper Abouar On

I just remplaced this :

Tag tag = audioFile.getTag();

By this :

Tag tag = audioFile.getTagAndConvertOrCreateAndSetDefault();

I use jaudiotagger2.2.7

To install it just add this in your buil project :

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
        maven { url "https://maven.google.com" }
    }
}

and this to your build module app (dependencies) :

implementation 'com.github.goxr3plus:jaudiotagger:2.2.7'