简体   繁体   中英

Get length of mp3 file

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?

尝试使用此getduration函数: http ://www.zedwood.com/article/127/php-calculate-duration-of-mp3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM