我有一个获取.WAV和.MP3持续时间的功能。对于.Wav来说,它工作得很好:06:31
但是对于.MP3,它什么也不返回。
任何人都可以帮助我进行调整:
function wavDur($file) {
$fp = fopen($file, 'r');
if (fread($fp,4) == 'RIFF') {
fseek($fp, 20);
$rawheader = fread($fp, 16);
$header = unpack('vtype/vchannels/Vsamplerate/Vbytespersec/valignment/vbits',$rawheader);
$pos = ftell($fp);
while (fread($fp,4) != 'data' && !feof($fp)) {
$pos++;
fseek($fp,$pos);
}
$rawheader = fread($fp, 4);
$data = unpack('Vdatasize',$rawheader);
$sec = $data['datasize']/$header['bytespersec'];
$minutes = intval(($sec / 60) % 60);
$seconds = intval($sec % 60);
return str_pad($minutes,2,'0', STR_PAD_LEFT).':'.str_pad($seconds,2,'0', STR_PAD_LEFT);
}
}
if (preg_match('/[.](wav)|(WAV)|(mp3)|(MP3)$/', $file)) {
$dur = wavDur($file);
} else {
$dur = '';
}