MP3 streaming code help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
brian183
Forum Newbie
Posts: 13
Joined: Thu Aug 26, 2004 1:28 am

MP3 streaming code help

Post by brian183 »

OK, I looked at the source code of a MP3 jukebox called kplaylist and found code for streaming (transcode) MP3.

Code: Select all

<?php
  $descriptorspec = array(
  0 => array('pipe', 'r'),
  1 => array('pipe', 'w'));
  $process = proc_open('c:/lame/lame.exe --silent --nores --mp3input -h -m s -b 128 "'.$_REQUEST&#1111;'file_to_stream'].'" -', $descriptorspec, $pipes);
  if(is_resource($process))
  &#123;
    while(!feof($pipes&#1111;1]) && !connection_aborted())
      echo fgets($pipes&#1111;1], 1024);
    fclose($pipes&#1111;0]);
    fclose($pipes&#1111;1]);
    proc_close($process);
  &#125;


?>
LAME 3.96.1 (stable) is used by this script.
It works sort of but while playing the streamed MP3...it only plays a part of the song. It's not a certain amount of time that gets cutoff the end of the song (ie. it'll play 9 seconds for one song while another could be 60 seconds). If anyone can help with this I'd appreciate it.
brian183
Forum Newbie
Posts: 13
Joined: Thu Aug 26, 2004 1:28 am

Post by brian183 »

ok I figured out whats wrong.

for some reason fgets doesn't work well with this. I replaced fgets with fpassthru and it works like a charm.

My next goal is to configure it for a ogg stream.
Post Reply