Does anyone know how I can get this script to work in Firefox? I'd be really grateful for any help. 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+"' 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); } //--> </script>
Do you have all plugins for firefox (LiveAudio) Try to see if you put the code directly if is working ... Regards
The problem is that it's only preloading the sound files for the IE and Netscape browsers. I'm looking for some code to add that will preload for Firefox. I think a few other people have this problem with this script as well. I've searched around on the net but no-one has come up with the answer. I'm hoping that the superior brainpower of the DP people will come up with something.
On second thoughts I decided it's better to post the code direct: /* * (C)2006 Stephen Chalmers * * This notice must not be removed * * Plays media files on hover to provide gratuitous * sound effects or talking tooltips. * */ /*** These instructions may be removed *** Installation and Configuration ============================== SAVE THIS TEXT/DOCUMENT AS: playmedia.js All the links that will play media files must be given a 'title' attribute, e.g. <A href='/content/index.htm' title='Contents Page'>Contents</A> There is no need to insert 'onmouseover' parameters to the links. At any point in the HTML file /below/ the last link, insert the following code. Note: If playmedia.js is located in a different folder, specify a relative path. <SCRIPT type='text/javascript' src='playmedia.js'> </SCRIPT> <SCRIPT type='text/javascript'> SCmediaPath=""; SCmediaDelay=300; SCmediaSetup( "title1", "file1.wav", "title2", "file2.wav", ........ ); </SCRIPT> The parameters passed to SCmediaSetup() above must be substituted with your own, as explained below. Example. You have three links whose titles are: "Products", "Ordering", and "Site Map" and you want to assign them the sound files: 'newprod.wav', 'ordering.wav', and 'map.wav' respectively. SCmediaSetup( "new products", "newprod.wav", "ordering", "ordering.wav", "site map", "map.wav" ); Notes ===== Not all the links in the document need be involved in playing sounds. Title / Filename parameter pairs need not be passed in the order in which the links appear in the document. The title specified for each link need not be its full title, a unique substring is sufficient, provided that it does not appear within the title of a different link. Thus the example above could have been written: SCmediaSetup( "new p", "newprod.wav", "ord", "ordering.wav", "map", "map.wav" ); This feature makes it very easy to configure all links to play the same file (if you must), by specifying a single character common to the titles of all the links. For instance, if all link titles end with a period (.), the following statement makes all links play 'blip.wav': SCmediaSetup( ".", "blip.wav"); Paths ===== If the sound files are located all together in a different folder, specify a /relative/ path in the SCmediaPath variable, otherwise leave it unchanged. For example, if the files are in a parallel folder called 'media', specify: SCmediaPath="../media/"; Alternatively, paths may be specified as a part of each filename parameter. Timeout ======= To prevent premature triggering, there is a default timeout of 400 milliseconds between mouseover and the instruction to play a file. The overall delay is dependent upon the particular plugin used. If the mouse cursor is removed before the timeout expires, the file is not played. Mute ==== To allow users to disable sound, place the following link anywhere in your HTML. <a href='#' onclick="toggleMediaPlay();return false">Sound Mute</a> Additionally, one could assign the link a title and have it play a wav file that says 'mute'. Operation ========= No media elements are created on startup, therefore when a link is hovered for the first time, there may be a short delay while the media plugin loads. This can be obviated by including a hidden embed tag like: <embed src='somefile.wav' hidden='true' autostart='false' width='0' height='0' hidden='true'> , however loading of the document will be commensurately delayed. If a media-playing link loads a new document in the current frame/ window, and the link is clicked immediately, there may not be time to play the file entirely or at all, as the script will be dismissed when the new page loads. This script is not coded to work in conjunction with other mouseover scripts operating on the same links. ******** DO NOT EDIT BELOW THIS LINE ************/ function SCmediaPlay(soundFile) { this.soundFile=soundFile; this.objRef=null; this.canPlay=true; this.tm=null; this.buffer=null; this.preLoad(); } SCmediaPlay.prototype.playSound=function() { if(this.canPlay) { if(this.objRef!=null) { document.body.removeChild(this.objRef); this.objRef=null; } if( (this.objRef=document.createElement('embed'))==null ) window.status="ERROR - Element not created: ["+(typeof this.objRef)+"]"; else { this.objRef.setAttribute("width","0"); this.objRef.setAttribute("height","0"); this.objRef.setAttribute("hidden","true"); this.objRef.setAttribute("src", this.soundFile); document.body.appendChild(this.objRef); } } } SCmediaPlay.prototype.preLoad=function() { this.buffer=new Image().src=this.soundFile; } String.prototype.contains=function(substr) { return new RegExp(substr,"i").test(this); } var SCmediaPath="", SCobjTable=[]; function SCmediaSetup() { if(document.body && document.body.appendChild) { for(var i=0; i<arguments.length; i+=2) for(var j=0, ll=document.links.length; j<ll; j++) if( document.links[j].title.contains( arguments[i] ) ) { var idx = SCobjTable.length SCobjTable[ idx ] = new SCmediaPlay( SCmediaPath+arguments[ i+1 ] ) document.links[ j ].onmouseover=new Function("SCobjTable["+idx+ "].tm=setTimeout('SCobjTable["+idx+"].playSound()', 400)"); document.links[ j ].onmouseout=new Function("clearTimeout(SCobjTable["+ idx+"].tm);if(SCobjTable["+idx+"].objRef){document.body.removeChild(SCobjTable["+ idx+"].objRef);SCobjTable["+idx+"].objRef=null;}") ; } } } function toggleMediaPlay() { for(var i=0; i<SCobjTable.length; i++) SCobjTable[i].canPlay^=true; } Code (markup):
Logic Ali, I tried to lower your set timeout-time.... It doesn't work to simply lower the numbers, could you like.. PLEASE send me the edited version so I can hear the sounds without waiting first.. They're supposed to be used for a menu, meaning every time the mouse goes over a text I hear this quiet BLIP. It doesn't work to hold the mouse over some item on the menu and then WAIT for the sound to come. Please please please please please send me the small piece of code I need to exchange with some of the old one in order to make it work... Please? /love
Hi, although this thread is old, the topic seems to be never ending. I've been looking for a week now for "audio onmouseover" scripts that start when you hover over an image or piece of text, and stop when you go away from the image or text (onmouseout) AND work with Internet Explorer and Firefox. I am under the impression that Firefox is still is - not to use the word crap - problematic with mouseover audio. I found a script which is working perfectly with Firefox, but I can't get it work with Internet Explorer. It goes like this: <html> <head> <script type="text/javascript"> function PlayIt(what){ document.getElementById('music').innerHTML='<object width="1" height="1" ' +'classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" ' +'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ' +'standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">' +'<param name="url" value="'+what+'">' +'<param name="uiMode" value="full">' +'<param name="autoStart" value="false">' +'<param name="loop" value="false">' +'<embed type="application/x-mplayer2" ' +'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" ' +'showcontrols="true" uimode="full" width="1" height="1" ' +'src="'+what+'" autostart="true" loop="false">' +'</object>'; } function stopIt(){ document.getElementById('music').innerHTML=''; } </script> </head> <body> <!-- Put in this code around the text or image where you want the mouseover effect to happen --> <a href="#" onMouseOver="PlayIt('mysong1.mp3')" onMouseOut="stopIt('mysong1')"><img src="Jellyfish.jpg" border="0" alt="whatever" width="300" height="225"/></a><p> </p> <a href="#" onMouseOver="PlayIt('mysong2.mp3')" onMouseOut="stopIt('mysong2')"><img src="Chrysanthemum.jpg" border="0" alt="whatever" width="300" height="225"/></a><br> <a href="#" onMouseOver="PlayIt('mysong3.mp3')" onMouseOut="stopIt('mysong3')">Play my song 3.</a> <!-- and this code too --> <div id="music"></div> <!-- Also wma files which are smaller than mp3 files do work. --> </body> I found and edited a liitle script which works perfectly with Internet Explorer 7 and 8, but - of course - not with Firefox. It goes like this: <html> <head> <script type="text/javascript"> function StartSound(soundobj) {var thissound= eval("document."+soundobj);thissound.Play();} function StopSound(soundobj) {var thissound= eval("document."+soundobj);thissound.Stop(); thissound.Rewind(); } </script> </head> <body> <!-- Put in this code around the text or image where you want the mouseover effect to happen --> <a href="#" onmouseover="StartSound('mysong1')" onmouseout="StopSound('mysong1')"><img src="Chrysanthemum.jpg" border="0" alt="whatever" width="300" height="225"/></a><p> </p> <a href="#" onmouseover="StartSound('mysong2')" onmouseout="StopSound('mysong2')"><img src="Jellyfish.jpg" border="0" alt="whatever" width="300" height="225"/></a><br> <a href="#" onmouseover="StartSound('mysong3')" onmouseout="StopSound('mysong3')">Play my song 3.</a> <!-- and put the following at the bottom of your page --> <embed src="mysong1.mp3" autostart="false" name="mysong1" enablejavascript="true" height="0" width="0"> <embed src="mysong2.mp3" autostart="false" name="mysong2" enablejavascript="true" height="0" width="0"> <embed src="mysong3.mp3" autostart="false" name="mysong3" enablejavascript="true" height="0" width="0"> <!-- All songfiles and the html file are in the same directory. --> </body> </html> Maybe it helps and maybe there will be some response and - very unlikely - a solution without flash. Mik