zeuskkc

Stream Audio Files Using PHP V-0.2

Aug 21st, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2. /* List of songs which will be streamed */
  3. /* Remember to add a complete link to your songs collection */
  4. $songs = [
  5.     'http://asian-city.tk/songs/Waqqaberry.mp3',
  6.     'http://asian-city.tk/songs/Fly_Project__Get_Wet.mp3'
  7. ];
  8.  
  9. /* No need to change anything bellow */
  10. set_time_limit(0);
  11. $bitrate = 128;
  12. $strContext=stream_context_create(
  13.     array(
  14.         'http'=>array (
  15.             'method'=>'GET',
  16.             'header'=>"Accept-language: en\r\n"
  17.         )
  18.     )
  19. );
  20.  
  21. /* Some required header stuff for streaming audio in html */
  22. header('Content-type: audio/mpeg');
  23. header ("Content-Transfer-Encoding: binary");
  24. header ("Pragma: no-cache");
  25. header ("icy-br: " . $bitrate);
  26.  
  27. /* Infinite Loop which repeat once the final song reach to its end */
  28. while( true ) {
  29.     /* Loop to stream each song in the list */
  30.     foreach ($songs as $song) {
  31.         /* Script for streaming */
  32.         $fpOrigin=fopen($song, 'rb', false, $strContext);
  33.         while(!feof($fpOrigin)) {
  34.             $buffer=fread($fpOrigin, 4096);
  35.             echo $buffer;
  36.             flush();
  37.         }
  38.         fclose($fpOrigin);
  39.     }
  40. }
  41. ?>
Add Comment
Please, Sign In to add comment