Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How can I get information (playing time) of mp3 audio files?

845492Apr 23 2012 — edited Apr 24 2012
I'm using the JavaZoom/Tritonus SPI implementation for decoding mp3 files. I have it installed correctly as I can open, decode, and play an mp3 file successfully. However, it's a terrible hack right now. I plan to simply read the mp3 file, convert it to WAV in memory, and then play/pause/seek with immediate response using the WAV format. In order to do this efficiently I need to know the size of the WAV format that will result from the decoding of the mp3 file. I am assuming that I can calculate this from the decoded format sample rate, sample size, channels, and length (in time). The first three I know as they are parameters for the target decoded format that I set. The last I cannot determine. I have found that using AudioInputStream.getFormat().properties() I can see two properties: vbr=false and bitrate=192000. On windows using Explorer I can see more information about the file than that, including length in mm:ss.

I can't figure out how to extract the play time length from the file. Can someone help? Thanks.

UPDATE:

I realized that I can at least generate an estimate of duration (time) using the encoded file length (in bytes) and the bitrate property (but not for variable bit rate I presume). That gets me close, but I'm still thinking there may be some metadata in the file that holds an exact value. I know my query for properties is not finding all the metadata in the file because when I view the file (in Explorer, or using Audacity or others) I can see there is artist, title, track, etc. metadata which I'm not seeing. Even using the method above to estimate duration, I need to find the length of the actual audio data, not including file/frame headers (I also presume this is not included in the bitrate value).

Edited by: ags - Updated
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 22 2012
Added on Apr 23 2012
3 comments
7,876 views