Having a terrible time trying to get the exact time to dial MP3 files. I have the 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 was not very lucky, so I was wondering if I am not doing something stupid, or if I can use the information in MP3 tags to calculate my actual length? Given that iTunes reports this correctly, I guess I should be able to.
source share