sellfisch Posted March 19, 2010 Share Posted March 19, 2010 Hello everybody, i try to stream a soundfile (while recording) with an php file to a embeded(vlc plugin) media player. The Problem is, that the soundfile is still growing, so it has no final filesize and php has to send everything. My actual version is: <?php header('Content-Description: File Transfer'); header('Content-Type: audio/x-wav'); header('Content-Disposition: attachment; filename=audio.wav'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); ob_clean(); flush(); $handle = fopen("audio.wav", "r"); while (!feof($handle)) { $buffer = fgets($handle, 4096); echo $buffer; } fclose($handle); //readfile("audio.wav"); Everything works fine if the playing offset is bigger that 10-15 secounds. Otherwise the download will be aborted (i think because php thinks that the end of file is reached). But need an offset of less than 3 secounds. I hope there is a solution without the need of a streaming server. Thanks for your help Quote Link to comment Share on other sites More sharing options...
nblasgen Posted April 9, 2010 Share Posted April 9, 2010 You're using fgets() which looks for \n's with a maximum of 4000 bytes read before returning. Wave files don't require \n's so this is a silly way to write the code. If the file isn't too big, I'd suggest looking at file_get_contents() but otherwise use something like fread() to read in 4k bytes. fgets() isn't designed for binary files anyays so it will return ASCII characters. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.