I am attempting to read a files audio length in Java using the following code:
return AudioFileIO.read(new File(audio)).getAudioHeader().getTrackLength() * 1000;
This works and gives me (roughly) the length of the audio file, but leaves an inputstream open, meaning that later on I cant delete the files, atleast not during runtime. This is problematic because Im using temporary files here and the directory needs to be cleared.
This is the output I get in my console:
Mai 06, 2023 10:30:13 PM org.jaudiotagger.tag.id3.AbstractID3v2Frame readIdentifier
WARNING: tmp0.mp3:No space to find another frame:
Mai 06, 2023 10:30:13 PM org.jaudiotagger.tag.id3.ID3v24Tag readFrames
WARNING: tmp0.mp3:Invalid Frame:tmp0.mp3:No space to find another frame
Mai 06, 2023 10:30:13 PM org.jaudiotagger.audio.mp3.MP3File readV2Tag
SEVERE: Could not invoke DirectBuffer method - illegal access`
This is the files metadata, according to (https://www.checkfiletype.com):
File Size 36 kB
File Type MP3
File Type Extension mp3
MIME Type audio/mpeg
ID3 Size 45
MPEG Audio Version 2
Audio Layer 3
Audio Bitrate 128 kbps
Sample Rate 24000
Channel Mode Single Channel
MS Stereo Off
Intensity Stereo Off
Copyright Flag False
Original Media True
Emphasis None
Encoder Settings Lavf58.76.100
Duration 2.30 s (approx)
I cant entirely seem to understand what the problem is thats making it throw that warning. Is the metadata faulty? If so, what can I do to fix it? Im getting the .mp3 through an API. Is there a different class I could use? The AudioSystem/AudioInputStream classes didnt work either and threw an error, saying the file type is unsupported.
Thanks in advance!