Results 1 to 7 of 7

Thread: on mouseover sound

  1. #1
    Join Date
    Sep 2008
    Posts
    36
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default on mouseover sound

    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:

    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:

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

    Adler

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    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.

    -magicyte
    Last edited by magicyte; 10-04-2008 at 11:38 PM.

  3. #3
    Join Date
    Sep 2008
    Posts
    36
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    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?

  4. #4
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    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

  5. #5
    Join Date
    Sep 2008
    Posts
    36
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    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

  6. #6
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    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

  7. The Following User Says Thank You to magicyte For This Useful Post:

    Adler80 (10-07-2008)

  8. #7
    Join Date
    Sep 2008
    Posts
    36
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    well, no worries. thanks for the effort anyway.

    take it easy

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •