<?php

require_once('getid3/getid3.php');
$getID3 = new getID3();

$filename = "MaryJane.mp3";

$ThisFileInfo = $getID3->analyze($filename);

$time = $ThisFileInfo['playtime_seconds']; //Extracts the plaing time of the mp3 file in seconds



$preview = $time / 30; // Set preview playing time here in seconds (Approximate)

$handle = fopen($filename, 'r');
$content = fread($handle, filesize($filename));

$oneSecond = round(strlen($content) / ($time)); //Determines string length for one second of playing time


$length = round(strlen($content) / ($preview));
$content = substr($content, $oneSecond * 10 , $length); // sets the start time in seconds, of the preview

header("Content-Type: {$ThisFileInfo['mime_type']}");
header("Content-Length: {$length}");

print $content;

?>