Written by: NetworkError, on 14-05-2008 21:05
Last update: 15-10-2008 21:30
Published in: Public,
Technical Wootness
Views: 943
When you download a file or stream a media file from a web server, the good ones will allow you to request portions of the file at a time. This gives you the ability to scan forward and backward through your media file or pause/resume a file download. You can do the same thing streaming a file through a PHP script.
You're probably asking why I want to do this in the first place. Well... Let's say I want to build a jukebox on my web server. All my friends come and login. They browser the music, make their selection, and the site gives them an m3u playlist file. They open the file in WinAmp or VLC and rock out for hours to my excellent collection.
Sounds great, yeah? But I don't want to give the world access to my music. So I keep my music in a non-web-accessible directory on my web server (or NAS). To get my music from the server to the client, I'll write a script that will act as a middle man. My m3u files will contain URLs with file ids and tokens associated with your login. When you pass a file id and a token, I'll stream your file. If you exceed your quota or your token expires, I stream you a 404 mp3 asking you to renew your session. (I could allow the user to re-activate their token, or just require them to re-download an m3u file with a new token.)
The URLs in my m3u files will look something like this:
#EXTM3U
#EXTINF:232,Bob Marley And The Wailers - Is This Love
http://networkerror.org/play_that_funky_music.php?file_id=1&token=1234
#EXTINF:429,Bob Marley And The Wailers - No Woman No Cry (Live)
http://networkerror.org/play_that_funky_music.php?file_id=2&token=1234
With all that out of the way, let's talk about how to go about streaming these files through PHP.