开发者

MP3 Duration Java

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

Now the file I am reading has a duration of 47:35 as reported by iTunes, and 48:50 using Mac Preview.

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);
            }

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.


Given iTunes is reporting it correctly I assume I should be able to.

One fail-safe way to determine the length of the track is to convert it into a standard AudioInputStream and then measure the AIS.

Or, as per the comment of @Kilian Foth:

Unfortunately, that is also the only fail-safe way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜