I want to make a simple script that will return the duration in the format mm:ss. My host does not support the id3 functions in php, even though I am running php 5.
I know the mp3’s bitrate, which is 64kbps, but the math that I tried doesn’t seem to work very accurately. Also, not all of the mp3’s are tagged the same, some have image tags, others don’t. I don’t know if this would attribute to the filesize, but I’m thinking it does.
[code=php]
$path = ‘song.mp3’;
$bytes = filesize($path);
$bits = $bytes * 8;
$krate = 64;
$brate = $krate * 1024;
$seconds = $bits / $brate;
$minutes = floor($seconds / 60);
$seconds -= $minutes * 60;
echo $minutes . ‘:’ . round($seconds,0);