Novated lease - MySpace Layouts - Find services - Find jobs - Wordpress Theme

PDA

View Full Version : onMouseover sound problem in Firefox


Trisha
Apr 3rd 2006, 7:52 am
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[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); }
//-->
</script>

sacx13
Apr 4th 2006, 8:21 am
Do you have all plugins for firefox (LiveAudio)
Try to see if you put the code directly if is working ...

Regards

Trisha
Apr 5th 2006, 5:52 am
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.

Logic Ali
Apr 18th 2006, 6:09 pm
[QUOTE=Trisha]Does anyone know how I can get this script to work in Firefox?

It's too 'orrible to touch.

I'm attaching one of my own creation. Read the instructions and notes carefully and you should find it quite simple to install and set up.
It's intended primarily to provide talking tooltips for links.

Ensure all your browsers are configured to use a suitable plugin for the file types you intend to use.

It seems to work O.K. under XP with the latest versions of I.E., FireFox, Netscape and Opera.

I'd be interested to know how others get on with it. To see/hear a working version of it, load the url below and mouse over the links in the top frame. As it says in the notes, response is not intended to be instantaneous.

http://www.hotspot.freeserve.co.uk/HOTSPOT/TLS/tlsframe.htm

--

Logic Ali
Apr 20th 2006, 8:10 am
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;
}

Thebutcha
Nov 18th 2009, 11:21 am
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