PDA

View Full Version : on mouseover sound



Adler80
10-04-2008, 07:53 PM
hey guys,

i have found some scripts for adding some sound to my page in a way that when one hovers the mouse on a picture the audio file will be played. but for some reason it doesn't happen!!! everything looks fine and i can't figure out what the problem is. can someone help me out please?

here is the javascript code:


var aySound = new Array();

aySound[0] = "myaudio.wav";

document.write('<BGSOUND ID="auIEContainer">')
IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0;
NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? 1:0;
ver4 = IE||NS? 1:0;
onload=auPreload;

function auPreload() {
if (!ver4) return;
if (NS) auEmb = new Layer(0,window);
else {
Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>";
document.body.insertAdjacentHTML("BeforeEnd",Str);
}
var Str = '';
for (i=0;i<aySound.length;i++)
Str += "<EMBED SRC='"+aySound[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>"
if (IE) auEmb.innerHTML = Str;
else {
auEmb.document.open();
auEmb.document.write(Str);
auEmb.document.close();
}
auCon = IE? document.all.auIEContainer:auEmb;
auCon.control = auCtrl;
}
function auCtrl(whSound,play) {
if (IE) this.src = play? aySound[whSound]:'';
else eval("this.document.embeds[whSound]." + (play? "play()":"stop()"))
}
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); }
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); }
//-->

and here is where I call the function:


<img alt="" src="mypicture.jpg" width="236" style="float:right" onMouseOver="playSound(0)" onMouseOut="stopSound(0)"/>

cheers,

Adler

magicyte
10-04-2008, 11:26 PM
Heh. This suggestion is a large cliche. Is your volume turned up?

Just kidding...

There is also another ancient way to do this with the BGSOUND tag (<BGSOUND></BGSOUND>). Here is an example of the BGSOUND:

<bgsound id="soud" src="exampleWav.wav" volume="-10000" loop="1000" autostart="false"></bgsound>

The volume is -10000 so that when you decide to start the sound, you turn the volume up (document.getElementById('soud').volume=0), the music plays. I've seen this done with other scripts and they work. You can use excerpts of code from here: Marionette 2 Webiste Example (http://plaza.harmonix.ne.jp/~jimmeans/mario2/).

-magicyte

Adler80
10-04-2008, 11:59 PM
hehe, nice one Magicyte!

well, i dont know a lot about coding and all, but am not that dumb ;)))

anyway, does that mean that nothing is wrong with the code? why doesn't it work then? the thing is, when i change that autostart value to "TRUE" the sound plays automatically when i open the page (hence the volume is up LOL) but it just doesnt work the way i want it to work on mouseover. what could be wrong?

magicyte
10-05-2008, 12:21 AM
I have some same problems with some similar code. The only problem was that my browser, for some reason, didn't support <embed>'s. I am pretty sure your code isn't full of any errors, but I am not so sure. I have a question: does it say that there is an error on the page? Once I know that, I can determine if your browser supports the type of HTML you provided or if your code is full of errors. Once again, I am sure your code isn't full of errors. What browser do you use and which version? I will MOST DEFINATELY be able to know what is wrong.

Also, PLEASE PROVIDE A LINK TO YOUR SITE SO THAT EVERYONE CAN SEE WHAT YOUR PROBLEM IS. Hope you answer soon.

-magicyte

Adler80
10-05-2008, 10:07 AM
Well, I don't think there is a problem with my browser since I use both IE7 and FF3.0.3 so at least one should respond if that's the case.

Anyway, I haven't put it on my site yet since I'm still testing it. so I just published a test page for you to see.

http://www.mobasser.me/soundtest.htm

Cheers,
Adler

magicyte
10-06-2008, 09:07 PM
I have no idea what to do. Your code looks feasible, but I may be wrong. If there are no errors and you browser is up-to-date, I don't know what to do so that your problem may be solved. I am terribly sorry.

-magicyte

Adler80
10-07-2008, 04:18 PM
well, no worries. thanks for the effort anyway.

take it easy