Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Playing Sound in a Web Page

We have a web application that was built several years ago. It uses .wav files containing sound clips. The sound clips are played when the user clicks a button on the web page.

The application has been in "mothballs" for several years. We recently recussitated it & now it fails in Internet Explore. It seems to work (sometimes) in Firefox.

The following is an example of the combination of HTML / Javascript that is used to play the sound clips.

(1) Form button looks like this:
<input type="button" value="Go" class="pt8" name="go1" onClick="EvalSound('sound1')">

(2) Javascript function EvalSound:
function EvalSound(soundobj) {
  var thissound= eval("document."+soundobj);
  thissound.Play();             
}

(3) sound1 defined:
<embed src="sounds/u2_q1_j.wav" autostart=false hidden=true name="sound1" enablejavascript="true">

When this is now run in IE 6.0, a Javascript Error occurs as follows:
"Object doesn't support this property or method.", line 79. Line 79 is
thissound.Play(); in the function EvalSound.

Why doesn't this work anymore? In Nov. 2005 it worked fine.
Avatar of avris
avris

Have you tried:
 var thissound= eval("document.getElementById('"+soundobj+"')")

<embed src="sounds/u2_q1_j.wav" autostart=false hidden=true id="sound1" enablejavascript="true">

?

1)
<form>
<input type="button" value="Play Sound" onClick="EvalSound('sound1')">
</form>
2)
<script>
function EvalSound(soundobj) {
  var thissound=document.getElementById(soundobj);
  thissound.Play();
}
</script>
3)
<embed src="success.wav" autostart=false width=0 height=0 id="sound1"
enablejavascript="true">

its because newer browsers doesnt support it anymore. :)
Avatar of Michel Plungjan
More likely Quicktime was installed since then and that plugin does not understand Play()
Avatar of Richard Korts

ASKER

To mplungian:

It needs to work on any computer regardless of whether Quicktime or Real Player are installed.

But as a test, should I uninstall Quicktime? I doubt that is the issue since it fails with a JavaScript error IN THE BROWSER.
To ilovemykeyki:

"its because newer browsers doesnt support it anymore. :)" - Can you provide me with code that will work WITHOUT requiring a QuickTime or RealPlayer plugin?
hi..i already put the code above. see the 2nd reply. thanks.
To ilovemykeyki:

I tried your code & it works! But there is one issue. It uses Real Player to play the sound & opens a Real Player object. Is there a way to minimize that object so that it DOES NOT appear on the screen?

Thanks,

rkorts
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial