0

Possible Duplicate:
PHP Function to get MP3 duration

I've currently got the following code for getting the video duration

$file = "videos/the_video.mp4";
passthru("ffmpeg -i ".$file." 2>&1");
$duration = ob_get_contents();
$search='/Duration: (.*?)[.]/';

$duration=preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE);
$duration = $matches[1][0];

How would I do this using a MP3 ?

Community
  • 1
  • 1

1 Answers1

1

If you want a solution without ffmpeg, you could use getID3:

http://getid3.sourceforge.net/

Source sample found here:

http://www.talkphp.com/general/2600-php-get-mp3-song-length.html

require_once('/path/to/getid3.php'); 

$getID3 = new getID3; 
$filename = "/path/to/mp3"; 

$ThisFileInfo = $getID3->analyze($filename); 
getid3_lib::CopyTagsToComments($ThisFileInfo); 

echo @$ThisFileInfo['playtime_string'];  
FWrnr
  • 361
  • 1
  • 6