You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java读取MP3时长后流未关闭及jaudiotagger警告问题求助

MP3时长读取的资源泄漏与元数据警告问题

当前代码问题

我用这段Java代码读取音频文件时长:

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

虽然能获取近似时长,但会让InputStream保持打开状态,导致运行时无法删除临时文件(需要清理临时目录)。

控制台输出的警告与错误

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

MP3文件元数据信息

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)

待解决的问题

  • 无法理解上述警告的产生原因,是否是MP3的元数据存在问题?
  • 如果是元数据问题,该如何修复?(文件来自API接口)
  • 有没有可替代的Java类用于读取音频时长?试过AudioSystem和AudioInputStream,但提示文件类型不支持。

内容的提问来源于stack exchange,提问作者Finn Andre Worm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 00:47:29