Solved

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

Posted on 1998-12-14
8
362 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 6

Expert Comment

by:PBall
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 6

Expert Comment

by:PBall
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now