php中怎么获取音频时长

getID3 是一个功能强大的 PHP 库,能解析多种音频文件格式并获取其详细信息,我们可以通过这个库来获取音频时长

首先安装getID3库

composer require james-heinrich/getid3

然后使用

<?php
require 'vendor/autoload.php';
use getID3;

$remotefilename = 'http://www.example.com/filename.mp3';
if ($fp_remote = fopen($remotefilename, 'rb')) {
    $localtempfilename = tempnam('/tmp', 'getID3');
    if ($fp_local = fopen($localtempfilename, 'wb')) {
        while ($buffer = fread($fp_remote, 8192)) {
            fwrite($fp_local, $buffer);
        }
        fclose($fp_local);
        $getID3 = new getID3;
        //获取音频信息
        $ThisFileInfo = $getID3->analyze($localtempfilename);
        //打印音频信息
        var_dump($ThisFileInfo)
        // 获取音频时长(以秒为单位)
        $duration = $ThisFileInfo['playtime_seconds'];
        unlink($localtempfilename);
    }
    fclose($fp_remote);
}

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: