Click to See Complete Forum and Search --> : playing sound from browser


pastet89
05-20-2010, 09:52 AM
Hi.
I am trying to run a sound in my web browser only when a defined event happens.
First of all, I want to tell you that I have tried a lot of different ways to play sound, but almost all of them require from the user addons like quick apple or etc... I want all of my users to hear the sound without exceptions!
Ok so, for that reason I tried with AC_RunActiveContent because I mentioned it on a website, which was working everywhere without any addons.
Here is my code:
HTML:

<html>
<head>
<script src="AC_RunActiveContent.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
function start() {

document.getElementById('mp3').innerHTML = eval('PejMiSlaveyu4udesni();');
}
function PejMiSlaveyu4udesni () {
// alert('Az sum funkciqta koqto pee i me puskat no ne peq!');
if (AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width', '1',
'height', '1',
'src', 'mp3.swf',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'false',
'scale', 'noscale',
'wmode', 'window',
'devicefont', 'false',
'id', 'mp3',
'bgcolor', '#333333',
'name', 'mp3',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', 'mp3',
'salign', ''
); //end AC code
}


}

<!--
function jsPlay(soundobj) {
var thissound= eval("document."+soundobj);
try {
thissound.Play();
}
catch (e) {
thissound.DoPlay();
}
}
//-->

</script>
</head>

<body onload="start();">
<div id="mp4"></div>
</body>
</html>




Javascript:
Please, view the code here: http://loffme.com/muzika/AC_RunActiveContent.js

I have also in the same directory a file named data.xml with the following content:

<mp3>
<track source="http://loffme.com/zvuk.mp3"/>
<track source="nika1izlezedaebe.mp3"/>
</mp3>


OK. All these works properly if puted in <body onload = "start();"> And now the prpoblems starts:
Problem number 1 is: As I am using mod rewrite from my .htaccess when I am in the not existing actually folder /search/ for example, the sound is not played, because the flash can not find the path to the mp3.swf, which is in the same dir, OR the path to data.xml, and the worst is that I even dont see where is the path to data.xml defined to change it!
I tried changing the path to mp3.swf, but without success. So my first question is how to get this workin in my virtual directories, created by the mod rewrite?
Problem number 2:
thats the strangest thing I have ever seen!!! I want that to be played not on load, but when somebody is writing in the chat and the user recieved the message the sound to be played. So I do sth like:

...here goes code for recieving message
if(newmessage) { start(); }

and it doesnt work and if I put:

...here goes code for recieving message
if(newmessage) { alert('I am playing'); start(); }
it outputs the alert and PLAYS????
WTF? It works only after an alert is called? Please, help, I am going crazy. I am trying to do this working last 3 days without success. And if you have better ideas for playing sound on event in browsers without addond, please put them here. Any help appreciated.

svidgen
05-20-2010, 11:06 AM
Double post: http://www.webdeveloper.com/forum/showthread.php?t=229935