Armado un script que genera un clip de 30 segundos de un archivo MP3 sobre la marcha. Si está buscando guardar el archivo, una de las otras opciones usando una clase/biblioteca será probablemente la mejor. Pero, si solo quieres reproducir/descargar la vista previa, sobre la marcha podría ser mejor. Definitivamente le ahorrará espacio en el disco duro.
Échale un vistazo al http://www.stephenwalcher.com/2013/06/17/how-to-extract-and-play-part-of-an-mp3-in-php/.
Aquí está el código, pero una explicación más profunda se puede encontrar en mi blog.
$getID3 = new getID3();
$id3_info = $getID3->analyze($filename);
list($t_min, $t_sec) = explode(':', $id3_info['playtime_string']);
$time = ($t_min * 60) + $t_sec;
$preview = $time/30; // Preview time of 30 seconds
$handle = fopen($filename, 'r');
$content = fread($handle, filesize($filename));
$length = strlen($content);
if (!$session->IsLoggedIn()) {
$length = round(strlen($content)/$preview);
$content = substr($content, $length/3 /* Start extraction ~10 seconds in */, $length);
}
header("Content-Type: {$id3_info['mime_type']}");
header("Content-Length: {$length}");
print $content;
I Don'y sé si algo ha cambiado en el lib getID3 o 'a es un error en su código: no hay elemento de longitud en la matriz id3_info. Debería ser playtime_string. – latata
El enlace está roto por cierto. –
Se corrigió el enlace. Debería ser bueno ir ahora. –