Solved

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

Posted on 1998-12-14
8
364 Views
Last Modified: 2012-08-13
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

// -->
0
Comment
Question by:netsurfer
  • 5
  • 3
8 Comments
 
LVL 6

Accepted Solution

by:
PBall earned 20 total points
ID: 1275643
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
 

Author Comment

by:netsurfer
ID: 1275644
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
 

Author Comment

by:netsurfer
ID: 1275645
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 6

Expert Comment

by:PBall
ID: 1275646
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
 
LVL 6

Expert Comment

by:PBall
ID: 1275647
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
 

Author Comment

by:netsurfer
ID: 1275648
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
 

Author Comment

by:netsurfer
ID: 1275649
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
 

Author Comment

by:netsurfer
ID: 1275650
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

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question