1

I have a folder full of audio files, a mix of mostly wma, mp3, wav, but also some obscure files like DS2 and aiff, on a VPS. The folder updates every day.

I am running a php based website using apache and MYSQL.

Is there anyway I can extract or somehow display a list of the audio files along with file durations for each?

I ideally need a solution that would allow a relatively non technical person to extract the data on a daily basis. So I'm thinking of displaying the data via a php file?

  • 1
    My title was inaccurate. I'm not just looking for mp3, but other formats too. Thus it's not a duplicate. Also the question incorporates how to parse the data in bulk. – user1522247 Apr 07 '15 at 21:50

1 Answers1

0

To get the MP3 duration, you have to use a custom class, because PHP doesn't have a builtin function doing that, i suggest you this one MP3File: .

After that you have to get all MP3s on the folder and display the name and duration:

require_one("mp3file.class.php");

if ($handle = opendir($dir)) { // $dir = your directory path
    while (false !== ($file = readdir($handle))) {
    $mp3file = new MP3File($file);
    $duration1 = $mp3file->getDurationEstimate();//(faster) for CBR only
    $duration2 = $mp3file->getDuration();//(slower) for VBR (or CBR)
        echo $file." - ". MP3File::formatTime($duration2)."\n"; // $duration1 for faster perfs
    }
    closedir($handle);
}
Akram Fares
  • 1,653
  • 2
  • 17
  • 32