Play wav in firefox
Hi all,
I need to play wav files in my Javascript which embedded in html. I found this example:
function playWav() {
if (imm_isIE) {
WavBar1.Run();
}
if (imm_isNS) {
document.WavBar1.stop();
document.WavBar1.setvol(100);
document.WavBar1.play(false);
}
}
But I am using firefox. There is no error but I couldn't hear anything when i run it. Is anyone has any idea? How could I fix it?
Thanks in advance,
masantha
Could be a plugin issue. If you're got a compatible plugin installed and that is configured correctly, then I know the following works in Firefox for WAV, MID, and MP3.
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us" >
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" >
<title> Music Test</title>
<script language="javascript" >
function playMusic(nm) {
obj = document.embeds[nm];
if(obj.Play) obj.Play();
return true;
}
function stopMusic(nm) {
obj = document.embeds[nm];
if(obj.Stop) obj.Stop();
return true;
}
function rewMusic(nm) {
obj = document.embeds[nm];
if(obj.Rewind) obj.Rewind();
return true;
}
</script>
</head>
<body>
<button type="button" onclick="return playMusic('myMusic');" > Play Music</button>
<button type="button" onclick="return stopMusic('myMusic');" > Stop Music</button>
<button type="button" onclick="return rewMusic('myMusic');" > Rewind Music</button>
<embed name="myMusic" src="../tunes/song.mid" type="audio/midi"
autostart="false" hidden="" loop="true" mastersound width="128" height="128" > </embed>
</body>
</html>
Hi phpnovice, thanks. It works!!
But actually in my case, I will need more than one wav files.
my JavaScript :
if (mx > 50 && mx < 80 && my > 40 && my < 90 {
Imm_EffectBar1();
return playMusic('myMusic');
}
else if (mx > 20 && mx < 40 && my > 10 && my < 40) {
Imm_EffectBar2();
return playMusic('myMusic1');
}
else {
IMM_endEffect();
return stopMusic('myMusic');
}
function playMusic(nm) {
obj = document.embeds[nm];
if(obj.Play) obj.Play();
return true;
}
function stopMusic(nm) {
obj = document.embeds[nm];
if(obj.Stop) obj.Stop();
return true;
}
In the html:
<embed name="myMusic" src="OneBeat.wav" type="audio/midi"
autostart="false" hidden="" loop="true" mastersound width="128" height="128"></embed>
<embed name="myMusic1" src="TwoBeat.wav" type="audio/midi"
autostart="false" hidden="" loop="true" mastersound width="128" height="128"></embed>
But seems the "myMusic1" won't stop once it starts. What can I do with it?
Thanks once again.
seanky
Originally Posted by
seanky
But actually in my case, I will need more than one wav files.
The obj.Play() method will accept arguments so that you can play multiple files withthe same EMBED object. I think they go something like this:
obj.Play(true, url); // play repeatedly
obj.Play(false, url); // play one time
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks