Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedd .wav files in HTML page in all browsers (no controls)

I need to play few wav files on button click. I found solution working in IE but it requires QickTime plugin for Firefox.

Is there any other way?

<html>
    <head>
        <script>
function DHTMLSound(surl) {
  document.getElementById("dummyspan").innerHTML=
    "<embed src='"+surl+"' hidden=true autostart=true loop=false>";
}
        </script>
    </head>
    <body>
        <h1>test</h1>
        <span id=dummyspan></span>
        <input type="button" value="Play" onmouseover="DHTMLSound('1.wav')">
    </body>
</html>
like image 738
Aramaki Avatar asked Nov 09 '09 10:11

Aramaki


2 Answers

Use one of these. I have only use jPlayer and can strongly recommend it.

jPlayer (requires Flash)

Scriptaculous plugin (works without Flash in Firefox)

MooTools (requires Flash)

like image 145
Sire Avatar answered Sep 24 '22 15:09

Sire


I'd detect whether the browser allows the audio tag, and use that in that case.

That looks like this:

<audio src="1.wav" autoplay></audio>

Currently Firefox, Safari and Opera can play Wavs, Chrome as of version 3 can't, not sure about 4.

See http://html5doctor.com/native-audio-in-the-browser/ for info on how to detect whether the browser has the audio tag.

You'd then use your existing solution for IE.

like image 41
Rich Bradshaw Avatar answered Sep 25 '22 15:09

Rich Bradshaw