24.4. Streaming Audio
Once upon a time, the only way to play audio from a web page was to link to it and wait for it to download to the hard drive so it could be played. With this method, once the file finishes downloading, the browser either launches an external player or uses a plug-in to play the audio.
Downloaded audio has a few distinct disadvantages. First, because the file needs to download to the hard disk in its entirety before it can begin playing, users may be faced with a very long wait before they hear any sound. In addition, because the audio file is copied to the hard drive, it is more difficult for artists and publishers to limit distribution and protect copyrights.
Although it is still possible and common to deliver static audio files in this manner, it is far more effective to use one of several streaming media technologies. Streaming media (be it audio or video) begins playing almost immediately after the request is made, and continues playing as the audio data is being transferred. Streaming audio technology was developed to address the problem of unacceptable download times. It can even be used to broadcast live programs, such as concerts or baseball games.
The following are some advantages to streaming audio:
Consider also these disadvantages:
24.4.1. Streaming File Formats
It used to be that if you wanted audio to stream, you had to use RealAudio technology. Not so anymore. As it became obvious that streaming was the best way to deliver sound to the Web, we've seen the development of a number of compteting proprietary technologies, as well as solutions for streaming standard file formats such as MP3 and QuickTime. The following formats have streaming functionality:
These file formats are discussed in more detail later in this chapter.
24.4.2. Server Software and Protocols
True streaming relies on special server software that permits the uninterrupted flow of data. The information in the song is broken up into little "packets" and sent out in order over the lines. These packets are then reassembled on the user's end. The audio player collects a number of packets before playback begins (a process called buffering) to increase the likelihood of smooth playback.
Streaming media takes advantage of either UDP (User Datagram Protocol), RTSP (RealTime Streaming Protocol), or RTP (RealTime Transfer Protocol) for the transmission of data. What makes these protocols effective at streaming is that if a packet of information is dropped or missing, the data transmission continues on without it. This is in contrast to traditional HTTP, the traditional protocol of the Web, which stops and tries to resend lost packets, potentially halting the stream.
UDP was the first protocol used for streaming media because of its improvements over HTTP. The newer RTSP is more efficent than UDP. RTSP is a two-way streaming protocol, allowing the user to send messages back to the server (such as rewinding the tape). By contrast, RTP (used by Apple QuickTime) is a one-way stream (similar to HTTP in this regard), only the file never downloads completely to the user's hard drive as it does in HTTP or FTP transfers.
Commercial streaming server software, such as RealServer, can handle thousands of simultaneous streams. It provides robust administrative tools and offers advanced functions such as bandwidth negotiation (where the proper bit rate version is delivered based on the connection speed). The software and hardware to set up a dedicated streaming server can be quite costly. On top of that, RealNetworks charges licensing fees based on number of streams.
Some media formats are designed to begin playing before they've completely downloaded, producing a streaming effect even when the files are served from an HTTP server. This is known as pseudo-streaming or HTTP-streaming.
The advantage to pseudo-streaming is that it requires no special (and costly!) server software. You just put the files on your server as you would a GIF or JPEG. This is a good solution for broadcasting relatively short audio tracks to just a few simultaneous listeners.
There are a number of key limitations to serving streaming media from a web server. It can not handle heavy server loads and multiple simultaneous connections. You also sacrifice the advanced administration tools and bandwidth negotiation (users have to choose the appropriate file for themselves). This method also makes it impossible to do live broadcasts since the whole file needs to be available for download.
With the proper player on the user's end, RealMedia, QuickTime, MP3, Flash, and Shockwave files will pseudo-stream from an HTTP server.
Copyright © 2002 O'Reilly & Associates. All rights reserved.