这是一个函数:
代码:
<?php
$f = 'somefile.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);
?>
样本输出:
Array
(
[Filesize] => 5108648
[Encoding] => CBR
[MPEG version] => 11
[Layer Description] => 01
[Protection Bit] => 1
[Bitrate Index] => 1010
[Sampling Freq Idx] => 00
[Padding Bit] => 0
[Private Bit] => 0
[Channel Mode] => 01
[Mode Extension] => 00
[Copyright] => 0
[Original Media] => 0
[Emphasis] => 0
[Bitrate] => 160
[Sampling Rate] => 44100
[Frame Size] => 523
[Length] => 252
[Length mm:ss] => 4:12
)
注意[Length mm:ss] => 4:12
部分。
另一种解决方案是使用外部工具,例如ffmpeg
或mp3info
与内置函数一起使用shell_exec()
。
资料来源: http ://www.zedwood.com/article/127/php-calculate-duration-of-mp3
希望这可以帮助!