Chapter 9: Multimedia

 <  Day Day Up  >  


One of the innovations that led to the development of the modern Web was the Mosaic browser's introduction of images in 1993 ”but this was just the first step toward the dream of a multimedia Web. These days, the Web can bring a variety of media forms ”including sound, video, and animation ”right to your browser or desktop. The last several years have seen a number of changes in this area of the Web, particularly where music distribution is concerned . This chapter looks at some of the latest, most popular technologies for Web multimedia, and how to include them in Web pages.

Audio

Few things are as persuasive as sound. Just try watching television with the volume muted; it's not terribly interesting. Sound is a vital element of true multimedia Web pages ”but how should sound be used? What Web audio technology is appropriate for the job? Simply adding a MIDI file to a site to provide continuous background sound may turn your page into the online equivalent of an in-store electronic organ demonstration. Audio support on the Web has seen a lot of changes in the past few years, and the emphasis has shifted greatly from playing music in Web pages to using external applications and stand-alone devices such as MP3 players, and independent, browser-enabled programs such as RealPlayer and RealJukebox. This section begins with a quick survey of sound and compression basics, reviews some older formats and approaches such as MIDI, and concludes with a look at MP3's impact and the current state of streaming audio as demonstrated by RealAudio. URLs in the text provide pointers to sites where you can learn more about these technologies.

Digital Sound Basics

Digital sound is measured by the frequency of sampling , or how many times the sound is digitized during a specific time period. Sampling frequencies are specified in kilohertz (KHz), which indicate the sound sampling rate per second. CD-quality sound is approximately 44.1 KHz, or 44,100 samples every second. For stereo, two channels are required, each at 16 bits; at 16 bits per sample, that yields 1,411,200 bits of data for each second of CD-quality sound. Like any other data, the bits of data on a CD could be delivered over the Internet, creating high-quality music at the end user 's demand. In reality, transmitting this amount of data would take nearly a T1 connection's bandwidth. Obviously, this type of sustained and guaranteed bandwidth is not available to the average home Web user. Even if it were, we may find that bandwidth across the Internet at large may not allow end-to-end throughput for thousands or millions of users simultaneously .

Given the cost of raw delivery, another approach is to lower the sampling rate when creating digital sound for Web use. A sampling rate of 8 KHz in mono might produce acceptable playback results for simple applications, such as speech, particularly considering that playback hardware often consists of a combination of a basic sound card and low quality speakers . Low-quality audio requires a mere 64,000 bits of data per second, but the end user may still have to wait to download the sound. For modem users, even in the best of conditions, each second of low-quality sound takes a few seconds to be delivered, making continuous sound unrealistic .

Audio File Formats and Compression

Like graphics files, audio files can be compressed to reduce the amount of data being sent. The software on the serving side compresses the data, which is decompressed and played back on the receiving end. The compression/ decompression software is known together as a codec . Just like image formats, audio compression methods are either lossy or lossless. Lossy data compression doesn't perfectly represent what was compressed, but is close enough, given the size savings. Because lossless compression techniques guarantee that what goes in one end comes out the other, most techniques can't compress files to any significant degree. Compression always involves a tradeoff between sound quality and file size; larger file sizes mean longer download times.

Downloading and Playing Audio

Early approaches to delivering sound via the Internet followed the "download and play" model, using formats such as WAV (waveform) files and AU (Sparc-audio, or u-law, format). In this scenario, users typically download sounds completely before they can play them. This takes up valuable hard drive space, even if a user wants to hear only the first few seconds of a file. Sounds must be degraded significantly in this situation, which might not be acceptable for content that requires flawless playback. Even at very low sampling rates, these sounds must be fairly short to spare impatient users the agony of prolonged download times. Download time can be reduced by creating smaller audio files, which only accentuates the drawbacks of this method.

Various older formats, such as AU and AIFF, are still in use on the Web, but are becoming less commonplace. One format that remains somewhat popular for this purpose is MIDI (Musical Instrument Digital Interface), which is often used with the Microsoft-specific < bgsound > tag discussed later in this chapter in the section "Audio Inclusion Basics." Netscape's LiveAudio technology once could be used to create a similar effect in conjunction with the < embed> tag, but LiveAudio now seems to have been dropped from more recent versions of Netscape and lacked cross-browser viability in any case. Most importantly, MIDI is not actually a digitized audio format, but represents notes and other information so that music can be synthesized . It can be a powerful tool for musicians when used with synthesizers and other electronic instruments, but MIDI files played back via PC sound cards often sound like cheap, synthesized music, which is more a reflection of the playback hardware than the protocol itself. Table 9-1 shows some of the older formats that might still be encountered on the Web.

Table 9-1: Older Internet Sound Formats

File Format

Description

WAV

Waveform (or simply wave ) files are the most common sound format on Windows platforms. WAVs can also be played on Macs and other systems with player software.

AU

Sparc-audio, or u-law format, is one of the oldest Internet sound formats. A player for nearly every platform is available.

AIFF

Audio Interchange File Format is very common on Macs. Widely used in multimedia applications, it is not very common on the Web.

MIDI

Musical Instrument Digital Interface format is not a digitized audio format. It represents notes and other information so that music can be synthesized. MIDI is well-supported and files are very small, but it is useful only for certain applications because its reproduction quality is often limited by PC playback hardware.

While many of the file formats listed in Table 9-1 may linger on the Web for quite some time to come, MP3 (MPEG Level 3) is really the only choice for high-quality, sampled audio playback. Not surprisingly, MP3 is the most popular form of audio file on the Web today.

MP3

MP3 is one of the formats for audio and video developed by MPEG (Moving Picture Experts Group) for transmission over the Web. MPEG Level 3 is an audio format that generally compresses CD-quality sound by a factor of about 10 “12 times, using techniques that were designed to take human audio perception into account, in order to minimize inaudible or unimportant frequencies and optimize the rest. Thus, a typical MP3 file (named for the format's file extension .mp3) of an average-length song weighs in at about 3MB, as opposed to the more than 30MB required for that same song on a compact disc.

In the last couple of years, this format has really taken off. The reason is simple: it provides high-quality audio that is not just suited for use on the Web, but in the real world as well, thanks to the increased availability of affordable CD copying devices, or burners. Music tracks from CDs can be converted to MP3 files, uploaded and downloaded across the Web, decompressed into CD-quality files, loaded onto MP3 players, or even burned to compact disc by anyone with a computer, a CD burner , and the right software. The grass-roots surge in MP3's popularity has, of course, generated considerable controversy. Regardless of the legal take on the various MP3- related battles , one thing is certain: the format has a very broad user base and will be around for quite some time.

Audio Inclusion Basics

Including download-and-play audio samples such as MP3 files in a Web page is simply a matter of using the anchor tag, <a>, to link to it. For example,

  <a href="thememusic.mp3">  Demo Company Theme Music  </a><br />   <a href="theme.midi">  Theme Music 2  </a><br />   <a href="robotsound.wav">  Robots in Action  </a><br />  

Assuming that users have the appropriate playback hardware and software when they click the link, the sound should be downloaded and then played. If they don't have the appropriate software, nothing may happen either.

Note  

There may be a problem that a Web server is not set up properly to deliver the associated sound files. If files play properly locally but seem to be downloaded as text or always prompt as an unknown type, you might have a problem with your Web server.

Even when everything is set up properly, it is a very good idea to let users know what they are getting into by indicating the file size, file type, and the fact that the object is a music file. For example,

  <a href="robotsound.wav" title="Play robot sound in Wav Format (10K)">   <img src="speaker.gif" alt="" height="10" width="10" border="0" />  Robots in Action  </a> [wav format / 10k]  

might look something like this:

If you are using an MP3 file, you may desire to make it play as it downloads or streams. It is actually quite easy to do this. Instead of a link to a file like thememusic.mp3, link to a small text file called thememusic.m3u. In that text file, put a single line of text indicating a URL to the actual MP3 file like http://www. yourservername .com/music/thememusic.mp3. Then just link to the m3u like so

  <a href="thememusic.m3u">  Demo Company Theme Music  </a><br />  

and you will have sound that should play as it downloads! However, even though this idea is much easier than complex streaming technologies discussed later, you still might want to embed a sound file directly within a page. There are a variety of ways to do this, the easiest being Microsoft's proprietary <bgsound> tag.

Microsoft's <bgsound>

Microsoft Internet Explorer 2 and later supports WAV and MIDI files directly using a <bgsound> tag, which plays a sound in the background after it is loaded. The tag takes an src attribute that is set to the URL of the sound file to play. The sound file must be in the appropriate format, either WAV or MIDI. A loop attribute, which can be set to an integer value indicating how many times the sound should play, is also available. The loop attribute can also be set to the value infinite to keep playing over and over. To play a sound called test.wav two times under Internet Explorer, for example, you could write <bgsound src="test.wav" loop="2">. Because the element is empty, there is, of course, no close tag. While it could be written to be XHTML-compliant as <bgsound src="test.wav" loop="2" / >, the value of doing so is limited considering this is a completely Internet Explorer proprietary element that won't validate. Volume can be controlled through the volume attribute, which has a value from “10,000 to 0, with 0 being full natural sound volume and -10,000 being volume off. While this range may seem unusual, it does work. The tag should occur within the body of a document. A complete tag example might look like this:

  <bgsound src="boing.wav" loop=3" volume="0" />  
Tip  

With <bgsound> , the user has no direct control over the volume or the playback of the sound, which may be annoying, so use sound carefully .

RealAudio

Download and play formats such as MP3 and even WAV are popular because they allow the transfer of high-quality audio files across the Internet ”but they were not really designed with the delivery demands of the Internet in mind. However, there is a strong desire, both among content creators and end users, to use the Web as a broadcast medium. The key to Webcasting is something called streaming . One of the most popular means of streaming audio is the RealAudio format developed by RealNetworks (www.realnetworks.com), which allows for the transmission of audio programming at a number of different speeds ”and even at multiple speeds, depending on the end user's requirements. But before we explore what can be done with RealAudio, it might be useful to take a closer look at streaming itself.

What is streaming? First of all, consider that a 28.8 Kbps modem user receives approximately 2K of data per second. If one second of sound could be represented in 2K, and the data could get to the end user at a rate of 2K every second, the data would effectively stream , or play in real time. Streaming seems to make a whole lot of sense. Why wait for an hour -long speech to download before playing when you care only about the current second of data being listened to? Streamed data doesn't take up hard drive space, and it opens up random access to any position in an audio file. However, streaming audio has a few potential serious drawbacks. First, to compress audio far enough for streaming, you have to sacrifice a certain degree of sound quality. Second, the Internet protocols themselves do not readily support the requirements of streaming. However, despite these problems, streaming music can be very effective and works more often than not.

The first ”and still the most popular ”approach to streaming audio was developed by RealNetworks. RealAudio uses a special server to send continuous audio data to a browser helper application, Netscape plug-in, ActiveX control, or RealNetworks' own freestanding RealOne Player. With players available for all major platforms, RealAudio is the most common streaming audio format on the Internet. Putting data in RealAudio format is fairly easy if the files exist in WAV or other common audio formats. Simply use the RealAudio production tools, which can be downloaded from RealNetworks, and the data is ready to publish. But despite RealAudio's wide support, it has certain drawbacks, which mostly revolve around the use of a special server.

Streaming servers can provide a higher degree of control. For example, they can limit or control the number of audio streams delivered and allow for easy access to specified points in an audio stream. With simpler " serverless " audio-streaming solutions, the virtual Fast Forward button provided by random access is sacrificed. Some sophisticated servers could potentially upgrade data quality as bandwidth becomes available. Less complex systems give the same quality of data regardless of the end-to-end access speed. Server-based systems are expensive and require computing resources beyond the basic Web server. RealAudio-based streaming audio servers have a per-stream cost for high-end sites that keeps some users from adopting this solution. Fortunately, entry-level RealAudio systems with a few streams are still free or very inexpensive, and RealAudio can also be streamed directly off an ordinary Web server, with certain limitations. Already, many organizations are using the RealAudio platform, which is a testament to the quality of the system.

RealAudio Basics

The first step in producing RealAudio content for the Web is to convert your existing audio files into RealAudio format, which is easy to do with the RealProducer program.

Note  

At the time of this writing, a free version of RealProducer is available for download from www.realnetworks.com/products/.

The second step is to link to the RealAudio content from a Web page by using the <a> tag, but there is a small nuance as you do not link directly to the .rm file created with a program like RealProducer but to a text file ending in the extension .ram:

  <a href="http://www.htmlref.com/audio/robotdrone.ram">  Hear our happy robots drone!  </a>  

This simple text file only needs to contain the URL of the .rm file you want to play:

 http://www.htmlref.com/audio/robotdrone.rm 

Assuming that the user has RealPlayer installed on the system being used, this will cause the RealPlayer program to pop open and begin playing the .rm file, as shown in Figure 9-1. RealAudio content can be played off any ordinary Web server, but content developers planning to reach a wide audience would be advised to look into the various RealServer packages available, which offer various levels of multiple stream support.

click to expand
Figure 9-1: RealAudio s RealPlayer

More complicated audio presentations that play a sequence of audio clips can be created by linking the .ram file to another file written in Synchronized Media Integration Language (SMIL), which should have the file extension .smil. SMIL can also be used to integrate video, text, and animations with your audio presentation.

Embedding RealAudio

RealAudio can also be embedded in a Web page using an <object> or <embed> tag. To use the <embed> tag, use a code fragment like this:

  <embed src="http://www.htmlref.com/audio/robotdrone.rpm"   nojava="true" height="100" width="250" autostart="false">  

Note that the file referenced ends in the extension .rpm, not .ram. This is the file type used in place of a .ram file when embedding RealPlayer in a Web browser. The .rpm file itself is just like the .ram file; it contains nothing more than the URL for the .rm file, but tells the browser to display the player inside the browser window rather than spawning the RealPlayer application in its own window, shown here in Netscape 7.

The autostart attribute determines whether the audio clip plays as soon as the page is loaded; if it is set to autostart="true" , the clip will start right away. When it is set to autostart="false" or omitted entirely, the audio clip will not start until the user clicks the Play button.

Note  

Referencing the .rm directly is also possible and generally appears to work in modern editions of RealPlayer.

It's possible that a user may not have a plug-in capability, so you may want to have a fallback with a link to the .ram file like so:

  <embed src="http://www.htmlref.com/audio/robotdrone.rpm"   nojava="true" height="100" width="250" autostart="false">   <noembed>   <a href="http://www.htmlref.com/audio/robotdrone.ram">  Hear our happy robots drone! (RealPlayer File)  </a>   </noembed>   </embed>  

To use the <object> tag, the code would look something like this:

  <object id="robotdrone"   classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"   width="75" height="30">   <param name="src"   value="http://www.democompany.com/audio/robotdrone.rpm" />   <param name="controls" value="PlayButton" />   </object>  

Again, the file referenced is an .rpm file. The id value can be set to any allowed value; however, the value shown for the classid attribute should always be clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA , as this identifies the RealAudio plug-in. The first parameter defined by a <param> tag is named src and has a value of the URL of the .rpm file. The second <param> tag sets what controls are displayed. In this case, it takes the PlayButton value, which displays a Play / Pause button, as shown here, in Internet Explorer.

Tip  

Because of cross-browser support issues, it might be sensible to avoid embedding RealAudio, and to simply rely on the RealPlayer program itself, which many users already are comfortable using.

While it is not within the scope of this book to go into great detail about RealAudio, this discussion should give you a brief glimpse of what can be done with this technology. For more specific information about how to use RealAudio technology, please see the RealNetwork's Web site.

WindowsMedia Audio

Needless to say, Microsoft has its own version of streaming media in the marketplace . After long consideration, they even went and named it WindowsMedia (windowsmedia.com). WindowsMedia supports the Microsoft-proprietary format known as Advanced Streaming Format (.asf). WAV files and MP3 files can be converted to this format using a tool named Windows Media Encoder. The technique for linking to an .asf file is similar to that used with RealMedia. In this case, simply link to a text file that ends with the extension .asx.

  <a href="robotdrone.asx">  Hear our happy robots drone!  </a>  

The format of the .asx file should be like this:

  <ASX version="3.0">   <ENTRY>   <REF href="robotdrone.asf" />   </ENTRY>   </ASX>  

Clicking the link to the .asx file causes the WindowsMedia Player to open and play the audio file. Again, since we understand the flavor of how audio is accessed from an HTML document, we leave the research of the specifics up to the adventurous readers as the details required to create such media is well beyond the scope of this book and even the markup syntax required has invariably changed.



 <  Day Day Up  >  


HTML & XHTML
HTML & XHTML: The Complete Reference (Osborne Complete Reference Series)
ISBN: 007222942X
EAN: 2147483647
Year: 2003
Pages: 252
Authors: Thomas Powell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net