AudioFileIO leaves inputstream opened after giving log warn "No space to find another frame"

huangapple go评论82阅读模式
英文:

AudioFileIO leaves inputstream opened after giving log warn "No space to find another frame"

问题

我试图在Java中使用以下代码读取文件的音频长度:

return AudioFileIO.read(new File(audio)).getAudioHeader().getTrackLength() * 1000;

这能够工作并给我(大致)音频文件的长度,但会保持一个输入流打开,意味着稍后我无法删除文件,至少不能在运行时删除。这是个问题,因为我在这里使用临时文件,需要清理目录。

这是我在控制台上得到的输出:

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

这是文件的元数据,根据(https://www.checkfiletype.com):

文件大小	36 kB
文件类型	MP3
文件类型扩展	mp3
MIME类型	audio/mpeg
ID3大小	45
MPEG音频版本	2
音频层	3
音频比特率	128 kbps
采样率	24000
通道模式	单声道
MS立体声	关闭
强度立体声	关闭
版权标志	否
原始媒体	是
强调	无
编码器设置	Lavf58.76.100
持续时间	2.30秒(约)

我似乎无法完全理解导致它抛出警告的问题。元数据有问题吗?如果是这样,我该如何修复?我是通过API获取.mp3的。是否有其他类我可以使用?AudioSystem/AudioInputStream类也不起作用,并抛出错误,说文件类型不受支持。

提前感谢!

英文:

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!

答案1

得分: 1

问题已通过将Maven依赖项从2.2.5增加到版本3.0.1来解决:

<dependency>
    <groupId>net.jthink</groupId>
    <artifactId>jaudiotagger</artifactId>
    <version>3.0.1</version>
</dependency>
英文:

The problem was fixed by increasing the maven depdendency from 2.2.5 to version 3.0.1:

&lt;dependency&gt;
    &lt;groupId&gt;net.jthink&lt;/groupId&gt;
    &lt;artifactId&gt;jaudiotagger&lt;/artifactId&gt;
    &lt;version&gt;3.0.1&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2023年5月7日 04:49:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76191069.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定