Embedding Sound in Web Pages, Part II: The Control Panel - Doc JavaScript

The Control Panel

The jukebox's control panel has a fairly simple design. It includes a select menu that displays the current song, a play button, a pause button, a stop button, volume control buttons, and a volume meter. The three control buttons (play, pause, and stop) are very similar in functionality to the volume buttons. As explained earlier, Navigator's implementation is based on the <A> tag, while the <IMG> tag is used for Internet Explorer. Let's take a look at the makeControlButtons() function:

One difference between these buttons and the volume ones is that the links specified by the <A> tags are actual functions to be executed, as opposed to javascript:void(0) function calls in the previous page. The reason for this difference is that we wanted the extra functionality of "volume sliding" via the onMouseDown and onMouseUp events. The Play, Stop, and Pause buttons rely only on the onClick event handler. The <A> tag's HREF attribute can execute a JavaScript function if its value is set to javascript:functionName() (e.g., HREF='javascript:play()'). The usage of <IMG> tag on Internet Explorer obviously does not provide such an option, so the onClick event handler is specified explicitly.

Notice that the control panel is made of a table with two rows and three columns. The top row includes one cell which spans all three columns, and hosts the pull-down menu. The bottom row includes three cells: the volume display, the volume controls, and the control buttons. We build the select menu by looping through the songs, and printing the corresponding

tag for each one. The onChange() event handler changes the song whenever the user changes the selection. The internals of the this event handler will be covered later in this column.

It is worth mentioning the difference in user interaction between the PC and the Mac. On the PC, the user can restart a paused track from the beginning, by clicking the Play button. On the Mac, on the other hand, clicking the Play button has no effect on a paused song. On both platforms, clicking the Pause button again resumes the song from its paused position.