Reputation: 163
Users upload mp3 files and I need to get their length. What is the least-effort way to do this in PHP? By least effort I mean whatever way requires the least amount of code and with as little non-native PHP functions as possible.
I tried implementing the code suggested in the answer below:
<?PHP
$f = 'numbers/4.mp3';
$m = new mp3file($f);
$a = $m->get_metadata();
if ($a['Encoding']=='Unknown')
echo "?";
else if ($a['Encoding']=='VBR')
print_r($a);
else if ($a['Encoding']=='CBR')
print_r($a);
unset($a);
?>
But I'm getting this error:
Fatal error: Class 'mp3file' not found in /home/a1865444/public_html/save-audio.php on line 3
How do I get around this?
Upvotes: 1
Views: 7973
Reputation: 1587
Try to use this getduration function: http://www.zedwood.com/article/127/php-calculate-duration-of-mp3
Upvotes: 2