Streaming from PHP

0

I am trying to create a striming from php, for this I use mp3 files to perform an automatic playback, until now everything works well for me. Here the code:

header("Cache-Control: no-cache, no-store");
header("Pragma: no-cache");
header("Expires: 0");
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="Straming";');
header('Content-Type: audio/mp3');

$path = "path/musicas/"; // Directorio

$tracks = [ 'pista_1.mp3', 'pista_2.mp3', 'pista_3.mp3']; //Ejemplo

$chunkSize = 1024 * 1024;

for($i = 0; $i < count($tracks); $i++ ) {

    $handle = fopen($path.'/'.$tracks[$i], 'rb');
    while (!feof($handle)){
        $buffer = fread($handle, $chunkSize);
        echo $buffer;
        ob_flush();
        flush();
    }
    fclose($handle);
    if($i == count($tracks) - 1 ) $i = -1; //Repetir Bucle

    /* Codigo de posible ejemplo
       $trackProg = bd->buscarProgramacion(date('y-m-d h:i:s'));
       if( $trackProg ){ //verificar si path o es falso
            //emitir
       }
    */
}

The client calls the file streaming.php on an audio tag (html5)

I also have a database where you keep what specific files should be played at a certain time. The structure of the programming table is as follows: id, path, date.

I want that at the moment of finishing to reproduce a music of the list, it is verified if there is a programming, to emit it.

I apologize if it's not like that, I do not know much about streaming, and I'm very limited in resources.

Thanks in advance!

    
asked by Islam Linarez 23.01.2018 в 00:41
source

0 answers