Playing sound (*.au or *.wav) OnMouseOver

Below is the "beep.js" file I am using which works great, but only for Netscape and I would like to have it work for IE as well. I just don't know the syntax to figure which browser and what the playsound function is for IE, could someone help? Basically I have image maps with embedded URL's that play a sound and show something in the status bar when the mouse pointer goes over it. I would like to get it working for IE, it already works for Netscape.
Thanks for the help.
In HTML file:
<SCRIPT type="text/javascript" src="beep.js">
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>

In Beep.js file:
<!--
function playSound(name) {
    if (navigator.appName== "Netscape" && parseInt(navigator.appVersion) >= 3 &&
        navigator.appVersion.indexOf("68k") == -1 && navigator.javaEnabled() &&
        document.embeds[name] != null && document.embeds[name].IsReady()) {
    document.embeds[name].play(false);
    }
}
onerror = null

// -->
netsurferAsked:
Who is Participating?
 
PBallCommented:
Take a look at the same question posted by someone in microsoft sitebuilder site.

http://www.microsoft.com/sitebuilder/magazine/webmen.asp#klickity

Basically they suggest putting an empty BGSOUND tag in the HEAD section

<BGSOUND id=objSound>

to play a sound just change the src property in javascript:

function playsound(sURL) {objSound.src = sURL;}

.onmouseover='playsound("/sounds/bang.wav")'
0
 
netsurferAuthor Commented:
Pball,
       If I understand your answer correctly, I need to change my OnMouseOver to reflect playsnd() instead of playsound() so that would work for IE, but then Netscape would'nt work. I need to change my beep.js to reflect the difference between IE and Netscape play sound commands and then have it play the proper one. Maybe I didn't make myself clear, but the difference in IE and Netscape play sound commands usable in the OnMouseOver command is what is confusing me. If I set it for one, the other won't work and visa-versa. Is there a way to dynamically change the command dependent upon which browser the end user has?

Thanks,
NetSurfer
0
 
netsurferAuthor Commented:
Here is the URL for my web based game that needs to be IE compatible for sounds, it already works for Netscape, I figured I'd give you this because it would make it easier to understand what I am trying to do.

Thanks,
NetSurfer
http://members.xoom.com/NetSurfer/course1.html
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
PBallCommented:
Yes, do browser detection routine at the beginning of the page.
<head>
<bgsound id=snd1>
<script>
IEPlus = False;

if (navigator.userAgent.indexOf("MSIE") != -1 &&
    navigator.userAgent.indexOf("Windows") != -1 &&
    navigator.appVersion.substring(0,1) > 3)
    IEPlus = True;

function playSound( name, sURL )
//name for Netscape
//sURL for IE
{
  if (IEPlus)
    snd1.src = sURL;
  else
  {
     if (navigator.appName== "Netscape" && 
         parseInt(navigator.appVersion) >= 3 &&
         navigator.appVersion.indexOf("68k") == -1 &&
         navigator.javaEnabled() &&
         document.embeds[name] != null &&
         document.embeds[name].IsReady())
       document.embeds[name].play(false);
  }
}
onerror = null;
</script>
<body>
<embed name=nsound1 src="blah.wav" ....>
<a href='...' onmouseover='playSound("nsound1","blah.wav")'>...</a>

0
 
PBallCommented:
There was a reference point for LiveAudio that supposedly you can replace the current source w/ other file, but so far, I am unable to make it work on Netscape.

document.NSnd.play(false,url_here)  doesn't work for some reason.

something to do w/ a stub wav file or something like that.

0
 
netsurferAuthor Commented:
Here is what I have done, I have a beep3.js file which contents are below.
My html file has the following in it and it seems to work fine for both IE and Netscape, but I cannot get my window.status to work in Netscape now.... It worked fine before, and works fine in IE, but I lost it somehow. I have tried using " instead of ' in the onMouseOver line, but it doesn't matter...Any ideas why?
HTML File
-------------
<HEAD>
<BGSOUND id=snd1>
</HEAD>
<SCRIPT type="text/javascript" src="beep3.js">
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>
<BODY>
<embed src="beep2.au" hidden="true" align="baseline" border="0" width="0" height="0" name="beep1" loop="FALSE" autostart="FALSE" mastersound>
<a href="beach2.html" OnMouseOver="playSound('beep1','beep2.au');window.status='BEEP!'; return true">...by placing your mouse pointer over this text until you hear a "BEEP",....</a>
=====================
Beep3.js
-------------
<!--
    function playSound( name, sURL )
     {
       {
         if (navigator.appName== "Netscape" &&
            parseInt(navigator.appVersion) >= 3 &&
            navigator.appVersion.indexOf("68k") == -1 &&
            navigator.javaEnabled() &&
            document.embeds[name] != null &&
            document.embeds[name].IsReady())
            document.embeds[name].play(false);
         else
            IEPlus = "False";
         if (navigator.userAgent.indexOf("MSIE") != -1 && 
            navigator.userAgent.indexOf("Windows") != -1 && 
            navigator.appVersion.substring(0,1) > 3)
            IEPlus = "True";
            snd1.src = sURL;
       }
     }
onerror = null
// -->
0
 
netsurferAuthor Commented:
Here is what I have done, I have a beep3.js file which contents are below.
My html file has the following in it and it seems to work fine for both IE and Netscape, but I cannot get my window.status to work in Netscape now.... It worked fine before, and works fine in IE, but I lost it somehow. I have tried using " instead of ' in the onMouseOver line, but it doesn't matter...Any ideas why?
HTML File
-------------
<HEAD>
<BGSOUND id=snd1>
</HEAD>
<SCRIPT type="text/javascript" src="beep3.js">
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>
<BODY>
<embed src="beep2.au" hidden="true" align="baseline" border="0" width="0" height="0" name="beep1" loop="FALSE" autostart="FALSE" mastersound>
<a href="beach2.html" OnMouseOver="playSound('beep1','beep2.au');window.status='BEEP!'; return true">...by placing your mouse pointer over this text until you hear a "BEEP",....</a>
=====================
Beep3.js
-------------
<!--
    function playSound( name, sURL )
     {
       {
         if (navigator.appName== "Netscape" &&
            parseInt(navigator.appVersion) >= 3 &&
            navigator.appVersion.indexOf("68k") == -1 &&
            navigator.javaEnabled() &&
            document.embeds[name] != null &&
            document.embeds[name].IsReady())
            document.embeds[name].play(false);
         else
            IEPlus = "False";
         if (navigator.userAgent.indexOf("MSIE") != -1 && 
            navigator.userAgent.indexOf("Windows") != -1 && 
            navigator.appVersion.substring(0,1) > 3)
            IEPlus = "True";
            snd1.src = sURL;
       }
     }
onerror = null
// -->
0
 
netsurferAuthor Commented:
i will put both test files out on my site if you want to look at them and see if I screwed something up. site address is http://members.xoom.com/NetSurfer/beach2.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.