Jump to content

Streaming wav-File through php


sellfisch

Recommended Posts

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

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.