PHP 获取音频文件播放时间长度

image

  • 安装getid3库。可以通过composer来安装,执行以下命令。
1
$ composer require james-heinrich/getid3
  • 在PHP文件中引入getid3库。
1
require_once 'vendor/autoload.php';
  • 使用getid3库来获取音频文件的信息,包括播放时间长度。
1
2
3
4
5
6
7
8
9
use getID3;

$getID3 = new getID3();
// 分析文件,$path为音频文件的地址(文件绝对路径)
$fileInfo = $getID3->analyze($path);
// 音频文件的播放时间长度,单位为秒。
$duration = $fileInfo['playtime_seconds'];

echo '音频文件的播放时间长度为:' . $duration . '秒';
-------------本文结束感谢您的阅读-------------
0%