MP3持续时间Java [英] MP3 Duration Java
问题描述
尝试获取一组MP3的准确时间非常麻烦.我具有使用 MP3SPI 1.9.5库生成的以下属性.
Having an awful time trying to get the accurate time for a set of MP3s. I have these following properties that are generated using the MP3SPI 1.9.5 library.
// mp3.crc=true
// mp3.copyright=true
// mp3.padding=false
// mp3.channels=1
// mp3.version.mpeg=2.5
// mp3.length.bytes=6425480
// mp3.framerate.fps=27.777779
// mp3.framesize.bytes=140
// duration=1606356000
// mp3.version.layer=3
// mp3.length.frames=44621
// mp3.frequency.hz=8000
// mp3.header.pos=0
// mp3.bitrate.nominal.bps=16000
// mp3.vbr.scale=0
// mp3.version.encoding=MPEG2DOT5L3
// mp3.mode=3
// mp3.vbr=false
// mp3.original=false
现在我正在读取的文件的持续时间由iTunes报告为47:35,而使用Mac Preview的持续时间为48:50.
Now the file I am reading has a duration of 47:35 as reported by iTunes, and 48:50 using Mac Preview.
当我使用库获得Java的持续时间时,我得到26:46:
When I get the duration in Java using the library I get 26:46:
AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(f);
Map<?, ?> properties = ((TAudioFileFormat) fileFormat).properties();
String key = "duration";
long duration = ((Long) properties.get("duration")) / 1000;
{
String frameBased = String.format("Duration Tag: %d hours, %d min, %d sec",
TimeUnit.MILLISECONDS.toHours(duration),
TimeUnit.MILLISECONDS.toMinutes(duration),
TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))
);
System.out.println(frameBased);
}
我运气不太好,所以我想知道我是不是在做一些愚蠢的事情,或者我是否可以使用MP3标签中的信息来计算我的实际身高?鉴于iTunes正确地报告了它,我认为我应该能够.
I'm not having much luck, so I was wondering if I'm doing something dumb, or if I can use the information within the MP3 tags to calculate my actual length? Given iTunes is reporting it correctly I assume I should be able to.
推荐答案
鉴于iTunes正确报告了它,我想我应该能够这样做.
Given iTunes is reporting it correctly I assume I should be able to.
一种确定轨道长度的故障保护方法是将其转换为标准的AudioInputStream
,然后测量AIS.
One fail-safe way to determine the length of the track is to convert it into a standard AudioInputStream
and then measure the AIS.
或者,根据@Kilian Foth的评论:
Or, as per the comment of @Kilian Foth:
不幸的是,这也是 only 故障安全方法.
这篇关于MP3持续时间Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!