Examples of Popups with Audio
via the overlibmws DHTML Popup Library maintained by Foteos Macrides at Macrides Web Services Discuss these examples, seek help, and offer suggestions for audio support via the overlibmws Support Group. These examples work best on broadband, but do work on dialup, and not badly once the audio files are in cache. |
I love my Harley. Chime in. Greek dances. |
The first example plays an audio file with looping while the user hovers over the link, whereas the second example plays an audio file once (i.e., without looping) per hover (onmouseover). The third example uses a playlist, with looping through the list, and random shuffling of the choices from the list on successive hovers over the link. The first two examples use procedures suited for relatively small audio files in one of the "old-fashioned" formats, e.g., .wav files as in these two examples, or .mid files. The third uses a freeware flash-based player for .mp3 files. Although it is geared toward sets of large files that can be problematic without broadband, such as the dance files in the third example, it also can be used with single, relatively small .mp3 files which "speak" the content of displayed DHTML popups, to increase their accessibility beyond the means disussed in the support document on keyboard-invoked popups. [Opera v9.5+ users see below] |
Here is the relevant javascript code and HTML markup: |
As a supplement to the overDiv positioned div for the visual display of popups, we declare an audioDiv positioned div for the concomittant audio presentations: |
<div id="audioDiv" style="position:absolute; visibility:hidden;
z-index:0;"></div>
|
It should be a direct child of the body (i.e., following the body start tag and not
encased in any other container element).
We then include markup which helps to "pre-load" our two .wav audio files and the image for the popup of the third example: |
<div id="harleyDiv" style="position:absolute; visibility:visible; z-index:0;
<div id="chimesDiv" style="position:absolute; visibility:visible; z-index:0;
<script type="text/javascript">
|
In the olden days of the original Netscape Navigator and the early Internet Explorer those embed elements would have been sufficient to play the audio files, and to stop them if the loop attritute is set to "true" such that the files do not stop themselves after single plays. For the first embed element we would use: |
onmouseover="document.myHarley.play(); return overlib(. . .);"
|
and for the second embed element we would use: |
onmouseover="document.myChimes.play(); return overlib(. . .);"
|
Internet Explorer still supports that simple mechanism, but alas, it has languished in the other browsers, with no intended simple alternative made available. We thus will use a "back door" strategy of also defining (via an imported .js file) the embed elements as string variables, with new name and id strings so that they remain unique across elements in the document, and with the autostart attribute set to true: |
var harley =
|
so that we can play an audio file simply by loading the corresponding string variable as HTML into our audioDiv postioned div. For the .mp3 file we define a string variable of the form flashMp3s# which points to our play list (or to others, if we had more play lists for this document). We also define a function which accepts that as its first argument, plus three more arguments associated with the flash-based player, and returns a string variable with an object and embed element set up for loading as HTML into our audioDiv: |
var flashMp3s01 = '../audio/misc/songlist01.txt';
|
Now we can define a playIt() function which manipulates these strings and loads our audioDiv: |
function playIt(whichsound, a1, a2, a3, a4) {
|
It has a required first argument which is either the name of an embed string variable (in this document, for our .wav audio files) or a function reference (name without parens) which in this document is for our flashMp3 function. The optional second through fifth arguments are for the first through fourth arguments of a flashMp3 function call, which is performed if at least one optional argument is present. |
We also define a stopIt() function: |
function stopIt(){
|
which we call onmouseout (together with an nd call) if the popup and audio were called onmouseover and the popup is not STICKY. For STICKY popups, which are closed via cClick calls, e.g., by the Close link in the CAPTION, we create a replacement which daisy-chains it to stopIt: |
var cClickOld = cClick;
|
Note that we use the replacement cClick in the body start tag: |
<body onunload="cClick();" onresize="cClick();">
|
to ensure that any audio associated with any open STICKY is terminated on leaving or resizing the current document. We still can simply minimize the current window and continue listening to the audio of a STICKY popup while working in another window. |
If we had secondary popups with audio, we correspondingly would define and use an audioDiv2 positioned div, and a playIt2, a stopIt2, and a replacement cClick2 function to use in conjunction with overlib2 and nd2 calls. |
|
We now are ready to make the calls for our popups with audio: |
|
I love my <a
|
|
<a
|
|
Greek <a
|
|
Opera v9.5+ issues: Note that these procedures all worked perfectly in Opera through version 9.27, but Opera v9.5 lost its handling of several attributes for embed elements, including hidden="true", autostart="false" and loop="true". The first doesn't matter in this context because we set the size to 1px, but both the Harley and Chimes sounds play, inappropriately, on document load, and the Harley sound doesn't persist on prolonged hover nor stop promply on mouseout. A bug report has been sent to the Opera folks, and hopefully they will restore handling of those attributes in a future release, but unfortunately the v9.6 release has remained lacking in this respect. Also note that the new Google Chrome browser does handle the embed element with these attributes properly. |
|
Use your browser's View Source option to see the javascript code, HTML markup, and CSS rules directly. |
|
|
Copyright Foteos Macrides 2002-2010. All rights reserved. |
|
|