Streaming audio/video from a web server
Introduction
Offering both an option to stream audio/video and to download the media will be appreciated by many users. Streaming enables almost instantaneous playback, irrespective of the duration of the content.
Streaming can be initiated with the help of redirector files (actually it's not streaming but progressive downloading). Linking to the redirector file will cause the associated player software to start on the client computer (if it's properly set up), and playback will start almost immediately (after buffering a small amount of data).
True streaming, as required for live/real-time content like net-radio requires a "streaming media server", a media server also has the advantage that the number of clients can be capped. This can sometimes be useful if many users accessing the media are swamping the available bandwidth, thereby degrading the service for all users. Normally however a plain http server will work fine for file based media.
Before continuing please read this brief explanation of file extensions and mime types on the web.
Creating redirector files
In the following code examples, replace yoursite.net with the domain and possibly path to your site. Note that the use of type attributes on the links is no substitution for supplying the correct mime type via the Content-Type http header.
MPEG layer 3
| Typical file extension | mp3 |
| Content | Audio |
- Use a text editor (for example Notepad on Windows) to create a music.m3u file with the full url to the actual mp3, for example: http://yoursite.net/music.mp3
- Upload the m3u file to the web server using ftp ascii mode.
- Upload the mp3 file to the web server using ftp binary mode.
- Set the proper mime type for both mp3 and m3u files on the web server; M3U Mime type: audio/x-mpegurl ; MP3 Mime type: audio/mpeg
- Link to the m3u file from HTML, for example:
<a href="music.m3u" type="audio/x-mpegurl">Play music</a>
Note: It's advisable to append a CR/LF after the url (hit enter so that there is a blank line beneath) in the m3u file as this seems to improve reliability for some clients.
Windows Media Audio
| Typical file extension | wma |
| Content | Audio |
- Use a text editor (for example Notepad on Windows) to create a music.wax file, an example of what to put in it:
<ASX VERSION="3.0"><ENTRY><REF HREF="http://yoursite.net/music.wma" /></ENTRY></ASX> - Upload the wax file to the web server using ftp ascii mode.
- Upload the wma file to the web server using ftp binary mode.
- Set the proper mime type on the web server for both wax and wma file types; WMA Mime type: audio/x-ms-wma ; WAX Mime type: audio/x-ms-wax
- Link to the wax file from HTML, for example:
<a href="music.wax" type="audio/x-ms-wax">Play music</a>
Windows Media Video
| Typical file extension | wmv |
| Content | Video + optional audio |
- Use a text editor (for example Notepad on Windows) to create a video.wvx file, an example of what to put in it:
<ASX VERSION="3.0"><ENTRY><REF HREF="http://yoursite.net/video.wmv" /></ENTRY></ASX> - Upload the wvx file to the web server using ftp ascii mode.
- Upload the wmv file to the web server using ftp binary mode.
- Set the proper mime type on the web server for both wvx and wmv file types; WMV Mime type: video/x-ms-wmv ; WVX Mime type: video/x-ms-wvx
- Link to the wvx file from HTML, for example:
<a href="video.wvx" type="video/x-ms-wvx">Play video</a>
Real Media files
| Typical file extension | rm |
| Content | Audio and/or video |
- Use a text editor (for example Notepad on Windows) to create a media.ram file with the full url to the actual real media file, for example: http://yoursite.net/media.rm
- Upload the ram file to the web server using ftp ascii mode.
- Upload the rm file to the web server using ftp binary mode.
- Set the proper mime type for both ram and rm files on the web server; RM Mime type : audio/x-realaudio ; RAM Mime type: audio/x-pn-realaudio
- Link to the ram file from HTML, for example:
<a href="media.ram" type="audio/x-pn-realaudio">Play video</a>
Ogg Vorbis
| Typical file extension | ogg |
| Content | Audio |
There is no dedicated redirector format for Vorbis audio, but 2 existing formats can be used:
M3U redirector files (.m3u)
Not ideal because it suggests that it links to an mp3 file. This won't be a problem for some players (Winamp 2 for example), but it's questionable whether or not you should rely on that. The advantage of using m3u files is that its file and mime type is often pre configured in modern web browsers and web server software.
- Use a text editor (for example Notepad on Windows) to create a music.m3u file with the full url to the actual Vorbis file, for example: http://yoursite.net/music.ogg
- Upload the m3u file to the web server using ftp ascii mode.
- Upload the ogg file to the web server using ftp binary mode.
- Set the proper mime type for both ogg and m3u files on the web server; M3U Mime type: audio/x-mpegurl ; OGG Mime type: application/ogg
- Link to the m3u file from HTML, for example:
<a href="music.m3u" type="audio/x-mpegurl">Play music</a>
Generic playlist files (.pls)
This is the preferred format, the drawback is that the file and mime type for playlist type files is usually not pre configured in web browsers and web servers, users generally need to be made aware of this and offered assistance via a "how to" page in getting it to work.
- Use a text editor (for example Notepad on Windows) to create a music.pls file with the full url to the actual Vorbis file, for example: http://yoursite.net/music.ogg
- Upload the pls file to the web server using ftp ascii mode.
- Upload the ogg file to the web server using ftp binary mode.
- Set a suitable mime type for both pls and ogg files on the web server; OGG Mime type : application/ogg ; PLS Mime type: audio/x-scpls
- Link to the pls file from HTML, for example:
<a href="music.pls" type="audio/x-scpls">Play music</a>
Ogg Media
| Typical file extension | ogm |
| Content | Video + audio |
Currently there is no established redirector file format for OGM files. These file and mime types are currently being used by some: mp4 as the file extension for the actual video file with an video/x-mpeg mime type, and m4u as the file extension for the redirector file with video/x-mpegurl as its mime type. This seems to make sense as it's analogous to the widely accepted way that mp3 and m3u files are named and served up.
M4U redirector files (.m4u)
- Use a text editor (for example Notepad on Windows) to create a video.m4u file with the full url to the actual OGM file, for example: http://yoursite.net/video.ogm
- Upload the m4u file to the web server using ftp ascii mode.
- Upload the OGM file to the web server using ftp binary mode.
- Set the mime type for both OGM and m4u files on the web server; M4U Mime type: video/x-mpegurl ; OGM Mime type: application/ogg
- Link to the m4u file from HTML, for example:
<a href="video.m4u" type="video/x-mpegurl">Play video</a>