Getting the title, artist / author and the duration of the .wav file

I am trying to get the properties of a file .wavthat I use in my Java project using the following code. However, when I run this code, methods format.getProperty("title"), format.getProperty("author")and format.getProperty("duration")all return null. Should I get this data in a different way?

AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(wavFile);
AudioFormat format = audioInputStream.getFormat();
Object[] temp = {false,
        format.getProperty("title"),
        format.getProperty("author"),
        format.getProperty("duration")};
+4
source share
1 answer

WAV files do not work well, although they may contain several types of metadata . Depending on the software and encoder used (16/32-bit PCM), you may have different configurations for the file, and the Java Sound API will have problems reading this metadata.

, (, Apache Tika, jd3lib, mp3agic, Beaglebuddy ..), MP3 , WAV.

-, : Jaudiotagger. , , , - :

AudioFile f = AudioFileIO.read(wavFile);
WavTag tag = (WavTag) f.getTag();

Object[] temp = {false,
        tag.getFirst(FieldKey.TITLE),
        tag.getFirst(FieldKey.ARTIST),
        f.getAudioHeader().getTrackLength() // In seconds
};

:

. ​​ 2.2.4 . .

+1
source

Source: https://habr.com/ru/post/1661070/


All Articles