Time Position in MP3

Blitz3D Forums/Blitz3D Beginners Area/Time Position in MP3

prefim(Posted 2003) [#1]
having found out that its much easier to use the playsound command than playmusic (as you get the pause, FF, REW etc.) the only task i cannot do so far is figure out where I am in a tune (ideally I want to figure out the time played/left of a song in MP3).

Anybody got any clues as to how to do this?

Cheers
Mat


soja(Posted 2003) [#2]
I've never done it before, but my take on it is that many players divide the file size by the bitrate to get the length of the song in seconds. (Note: Of course this wouldn't work in formats like MIDI or MOD since the information is stored and played completely differently.)

So for example, a 6MB MP3 compressed with 192Kbps bitrate:
6MB = 6144KB
192Kb/s = 24KB/s
...
6144KB/24KB/s = 256s = 4:16 (m:s)

And of course to get how long it has played, you just have to keep track of how many KB you've read in the file.

Like I said, I'm not absolutely sure, but it seems to work out. And what led me to this assumption is seeing my music player (Quintessential) always changing the approximate length of the song (and getting it wrong) every second or so on variable bitrate files.