PHP code example of leequix / icecast-streamer

1. Go to this page and download the library: Download leequix/icecast-streamer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

leequix / icecast-streamer example snippets




use IcecastStreamer\Stream;
use IcecastStreamer\Stream\MountPoint;
use IcecastStreamer\Stream\Connection;
use IcecastStreamer\Stream\AuthCredentials;
use IcecastStreamer\Stream\Info;

$mountPoint = new MountPoint('/live', new AuthCredentials('source', 'hackme'));
$connection = new Connection('localhost', 8000, $mountPoint);
$info = new Info();
$info->setContentType('audio/mpeg');
$info->setName('Super cool stream');
$info->setDescription('My first stream');
$info->setGenre('drum and base');
$info->setUrl('http://leequix.xyz');
$stream = new Stream($connection, $info);

try {
    $stream->start();
} catch (Exception $exception) {
    echo $exception->getMessage();
}

$file = fopen('./imperial_march.mp3', 'r');

while ($data = fread($file, 24567)) {
    $stream->write($data);
    echo ('[' . date('H:i:s') . '] I am send ' . strlen($data) . ' bytes of data!' . PHP_EOL);
    sleep(1);
}

fclose($file);
$stream->stop();