Doctor of Science in Information Technology (DScIT) Repository

9.2 - Playing Audio

Playing Audio

Audio files can be downloaded from the Web for local playback. Audio files in MPEG and WAV formats are the most common types for downloads. Audio files can also be streamed from a media server computer. These can be in the form of live broadcasts or digitized files for on-demand retrieval. WMA format is a popular Windows format for streamed audio.

Linking to Audio Files - TOP

An audio file is made available for download and playback by placing it in your Web directory. Access to the file is through a simple link using an <a> tag coded with the relative URL to the file. When the link is clicked, the file is opened on the client's desktop in the external Media Player. The player provides progressive download so that the user does not have to wait for the entire file to download before playback begins. After the file is downloaded, it becomes available on the user's PC and can be replayed locally.

The following graphic and text links would connect to a WAV audio file appearing in the same directory as this Web page. Clicking on a link would open the external Media Player for file download and playback. The exact appearance of the Media Player on your desktop depends on how it is configured.

An example of how this would be coded is shown below. The href attribute of the  <a>  tags surrounding both the graphic image and text are URLs for the local WAV audio file.

    <a href="PeopleWillCome.wav"><img src="PeopleWillCome.gif" alt="Kansas ballpark"/></a>
    <a href="PeopleWillCome.wav">PeopleWillCome.wav (426 KB)</a>

Listing 9-1. Code to link to audio file.

The <audio> Element - TOP

HTML5 introduced a new <audio> tag for standardizing the way audio files can be played in a browser. Codecs for audio can still differ between different system types, so for fallback functionality you may need to supply multiple sources to an audio  element. The browser will try to load the sources in order, and if it cannot use a <source>  it will display the error message.

<audio controls>
  <source src="PeopleWillCome.wav" />  
  <source src="PeopleWillCome.mp3" />
  Your browser does not support the audio tag.
</audio>

TOP | NEXT: Playing Video