[asterisk-users] OT - How to stream a A-Law/wav file to a browser ?

Olivier oza-4h07 at myamail.com
Thu Sep 18 12:05:28 CDT 2008


2008/9/18 Gordon Henderson
<gordon+asterisk at drogon.net<gordon%2Basterisk at drogon.net>
>

> On Thu, 18 Sep 2008, Olivier wrote:
>
> > Hi,
> >
> > How can I create a web page allowing people to listen (with their own PC)
> a
> > couple of .wav/a-law files stored on a Linux server ?
> > Chances are users would access this web page from Internet Explorer but
> if I
> > could make it available to other browsers, that would be better.
> >
> > I googled a bit and couldn't find a tag such as media://myaudiofile.wav
> that
> > would fulfill this spec.
>
> If the web server is running php,


You read in my mind : it will certainly run php !

> then this will work:
>
> <?
>
>   $action = $HTTP_GET_VARS["action"] ;
>   $file   = $HTTP_GET_VARS["file"] ;
>   $caller = $HTTP_GET_VARS["caller"] ;
>
>   if (empty ($action) || empty ($file))
>     die ("Something went wrong")  ;
>
> // Open the file
>
>   $fileName = "/prefix/" . $file ;
>   $fd       = @fopen ($fileName, "rb") ;
>
>   if ($fd === FALSE)
>     { Header ("Location: " . $caller . ".php?error=1") ; die () ; }
>
> // Send the headers to the browser
>
>   $len = filesize ($fileName) ;
>
>   Header ("Accept-Ranges: bytes");
>   Header ("Content-Length: $len") ;
>   Header ("Keep-Alive: timeout=2, max=100") ;
>   Header ("Connection: Keep-Alive") ;
>   Header ("Content-Type: audio/x-wav") ;
>
>   if ($action == "download")
>   {
>     Header ("Content-Disposition: attachment; filename=\"$fileName\"");
>     Header ("Content-Description: File Transfer");
>   }
>
> // Transmit the file in 8K blocks
>
>   while (!feof ($fd) && (connection_status () == 0))
>   {
>     set_time_limit (0) ;
>     print (fread ($fd, 1024*8)) ;
>     flush () ;
>   }
>
>   fclose ($fd) ;
>
> ?>
>
> If this was called playback.php, then you'd reference it in other HTML
> code with:
>
>   <a href="payback.php?action=play&file=music.wav&caller=thisFile">Click
>        here to play</a>
>
> I've found that seems to let most browsers play (or download) most audio
> files, (most of the time ;-)
>
> The browser will (should) do whatever it's configured to do with audio
> files. I use this to let people playback voicemail and call recordings.


Is that all ?
You just have to specify "Content-Type: audio/x-wav" and it will work with
an Internet Explorer browser ?
That's good news for me.

Thanks for sharing this.

Cheers


>
> Gordon
>
> _______________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> AstriCon 2008 - September 22 - 25 Phoenix, Arizona
> Register Now: http://www.astricon.net
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>   http://lists.digium.com/mailman/listinfo/asterisk-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20080918/1c44858e/attachment.htm 


More information about the asterisk-users mailing list