Link to home
Create AccountLog in
Avatar of Chi Is Current
Chi Is CurrentFlag for United States of America

asked on

Play wav sound upon link click

Hello ~

I'd like to play a .wav file on a web page when I click a link.  I found the following script on EE circa 1997, and am not getting it to run.  

Page: 1index.html
File to play: Bark1a.wav
Text link: BARK! - Work in Progress

The 'Bark1a.wav' file does reside in the same directory as the '1index.html' page.

I would appreciate your assistance.

============================

</head>
<SCRIPT LANGUAGE="JavaScript">
function start()
      {
      document.1index.html.play(false);
      }
</SCRIPT>


<BODY>

<EMBED SRC="Bark1a.wav" HIDDEN=TRUE AUTOSTART=FALSE NAME="1index.html" MASTERSOUND>

<a href="JavaScript:start();">BARK! - Work in Progress</A>

============================

Many Thanks, Jacob
ASKER CERTIFIED SOLUTION
Avatar of Richard Davis
Richard Davis
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Most of the methods of playing/controlling sounds in Javascript involve using <embed> to embed a WAV file in the page. The problem is it requires that WMP be installed, and the user gets an "ActiveX Warning" on the page and has to accept for it to work.

Someone released a Flash based WAV file player. It's invisible, you put it on the page, and then use Javascript to send commands to Flash. Flash handles the playing of all the sound files. Looked pretty nifty to me.

http://ajaxian.com/archives/soundmanager-2-a-sound-api-for-javascript

download page:

http://www.schillmania.com/projects/soundmanager2/
Avatar of Chi Is Current

ASKER

Thank you both for your ideas.

Adrian ~  Your solution appears easy to implement.

However, when I place the code on my page, it doesn't play the sound.

If you could have a look:

http://begnbark.com/1index.html

???
Adrian ~

I'm attempting option #4 on your example.

In the script, do I need to replace 'document' with my file name (1index.html)? :


<script>
function EvalSound(soundobj) {
  var thissound=document.getElementById(soundobj);
  thissound.Play();
}
</script>

<embed src="Bark1.wav" autostart=false width=0 height=0 id="sound1"
enablejavascript="true">

<BODY>
The button form is written:

<form>
<input type="button" value="Play Sound" onClick="EvalSound('sound1')">
 </form>


Adrian ~

OK ~  I had the name written incorrectly for my .wav file.

'Script works GREAT.  Fast!!!

Thanks!!!

Jacob
Great!  Thank you!  I'm a big fan of elegant simplicity.

Best Regards, Jacob
Sorry for not responding back to your additional questions, but gad that it proved helpful from that page I sent you. :)

Take care

~AB