Page 1 of 1

MP3 streaming code help

Posted: Thu Aug 26, 2004 1:28 am
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.

Posted: Fri Aug 27, 2004 6:07 pm
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.