Embedding Audio with RealPlayer


The preceding section showed you how the <object> tag can be used to embed Windows Media Player into a web page so that a video clip could be played. But what if visitors to your web site are using some other media player such as RealPlayer? Changing the <object> tag to use a different player is primarily a matter of providing the appropriate classid for the desired player.

By the Way

RealAudio is a streaming audio format that was popularized by the RealPlayer media player. To download a free version of RealPlayer, visit http://www.real.com/player/.


The following code shows how to play a RealAudio audio clip using RealPlayer:

 <object class width="290" height="65">   <param name="type" value="audio/x-pn-realaudio-plugin" />   <param name="src" value="http://wiredforbooks.org/alice/chapter1.ram" />   <param name="controls" value="All" />   <param name="loop" value="false" />   <param name="autostart" value="true" />   <embed width="290" height="65" type="audio/x-pn-realaudio-plugin"   src="/books/4/158/1/html/2/http://wiredforbooks.org/alice/chapter1.ram" controls="All"   loop="false" autostart="true" pluginspage="http://www.real.com/player/" /> </object> 


In this example, the RealAudio clip chapter1.ram is played using an embedded RealAudio player. Several <param> tags are required in order to get the player properly initialized. For example, the type parameter sets the standard MIME type for RealAudio, which helps the player know what type of media is being played.

You've probably noticed that the remaining parameters don't all match exactly with the earlier parameters you saw for the embedded Windows Media Player object. This is because each media player is free to define its own parameters. Fortunately, the parameters across media players are reasonably similar.

The src parameter for RealPlayer identifies the URL of the multimedia content, and controls is similar to uiMode in the Windows Media Player control. The loop and autostart parameters control whether the clip loops repeatedly, as well as whether it immediately starts playing when the page is opened.

I'm sure you also noticed that I included an <embed /> tag within the <object> tag to accommodate older and inconsistent web browsers.

Listing 19.3 shows the RealPlayer control as it appears within a real web page.

Listing 19.3. The <object> Tag Is Used to Embed a RealAudio Audio Clip Directly in a Page
 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">   <head>     <title>Alice's Adventures in Wonderland</title>   </head>   <body>     <div>       <h1>Alice's Adventures in Wonderland</h1>       <h2>By Lewis Carroll</h2>       <p>         This audio production of Lewis Carroll's "Alice's Adventures in         Wonderland" was made possible by <a href="http://wiredforbooks.org/">         Wired for Books</a>. To listen to the complete recording, visit the         <a href="http://wiredforbooks.org/alice/">Alice page</a> at the Wired         for Books Web site.       </p>       <p>         <object class         width="290" height="65">           <param name="type" value="audio/x-pn-realaudio-plugin" />           <param name="src" value="http://wiredforbooks.org/alice/chapter1.ram" />           <param name="controls" value="All" />           <param name="loop" value="false" />           <param name="autostart" value="true" />           <embed width="290" height="65" type="audio/x-pn-realaudio-plugin"           src="/books/4/158/1/html/2/http://wiredforbooks.org/alice/chapter1.ram" controls="All"           loop="false" autostart="true"           pluginspage="http://www.real.com/player/" />         </object>       </p>     </div>   </body> </html> 

Figure 19.4 shows the Alice in Wonderland RealAudio clip as it is being played via the embedded RealPlayer control. This clip is made available by Ohio University's Wired for Books web site, which is located at http://www.wiredforbooks.org/.

Figure 19.4. Playing embedded audio is possible with a combination of the <object> and <embed /> tags, including such interesting audio as a popular book being read aloud.


This example shows how a web page can be used as the basis for listening to an audio book, which is possibly something you've never considered. You could even record and place your own audio clips on a site and play them back in this manner. Many businesses and organizations are using such an approach to post regularly scheduled audio messages on their web sites.

Did you Know?

Whenever you set up a web page to play a sound automatically, it's a good idea to give people some way to turn the sound off. (There's nothing more annoying than surfing the Web with your favorite CD on and hitting a musical web page that can't be turned off!) In the Alice in Wonderland example, the RealPlayer media controls are fully accessible, giving the user plenty of options for controlling how the audio is played.





SAMS Teach Yourself HTML and CSS in 24 Hours
Sams Teach Yourself HTML and CSS in 24 Hours (7th Edition)
ISBN: 0672328410
EAN: 2147483647
Year: 2005
Pages: 345

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