princehyderabad
asked on
onLoad Play Sound
hi,
Can anyone tell me whtz the easiest way to load a .wav file on page load and when click on the speaker image it should stop playing.
ie.. on page load default .wav will start playing, click <Speaker> will stop playing .wav, Click <Speaker> again will start playing .wav
Thx,
H
Can anyone tell me whtz the easiest way to load a .wav file on page load and when click on the speaker image it should stop playing.
ie.. on page load default .wav will start playing, click <Speaker> will stop playing .wav, Click <Speaker> again will start playing .wav
Thx,
H
ASKER
I got you, but how about stoping it !!!
Autostart on page load, fine but when user dont wanna listen and wanna read the text how can he stop???
Autostart on page load, fine but when user dont wanna listen and wanna read the text how can he stop???
<embed name="snd" SRC="/sounds/mattdum.mid" autostart="true">
<input type="button" value="Stop" onclick="document.snd.stop ()">
<input type="button" value="Play" onclick="document.snd.play ()">
<input type="button" value="Stop" onclick="document.snd.stop
<input type="button" value="Play" onclick="document.snd.play
ASKER
Okay here is case:
I have page on load it autostart audio fine, anybody can do that, but I have only one Speaker Image, if I click that the autostarted audio should stop. And if I wanna hear again, I would click the same Speaker Image and it should start playing. Same Image, on 1 click stop, on other click play.
hope this is more clear.
I have page on load it autostart audio fine, anybody can do that, but I have only one Speaker Image, if I click that the autostarted audio should stop. And if I wanna hear again, I would click the same Speaker Image and it should start playing. Same Image, on 1 click stop, on other click play.
hope this is more clear.
<embed name="snd" SRC="/sounds/mattdum.mid" autostart="true">
<input type="button" value="Play/Stop" onclick="if(stopped){stopp ed=false;d ocument.sn d.play()}i f(!stopped ){stopped= true;docum ent.snd.st op()}">
stopped variable must be defined first
<input type="button" value="Play/Stop" onclick="if(stopped){stopp
stopped variable must be defined first
ASKER
can you plz define stopped variable, bcoz I dont know all this JS... pleasee
sure
<html>
<head>
<script language="Javascript">
var stopped=true;
function play_(){
if(stopped){
stopped=false;
document.snd.play()
}
if(!stopped){
stopped=true;
document.snd.stop()
}
}
</script>
</head>
<body>
<embed name="snd" SRC="/sounds/mattdum.mid">
<input type="button" value="Play/Stop" onclick="play_()">
</body>
</html>
<html>
<head>
<script language="Javascript">
var stopped=true;
function play_(){
if(stopped){
stopped=false;
document.snd.play()
}
if(!stopped){
stopped=true;
document.snd.stop()
}
}
</script>
</head>
<body>
<embed name="snd" SRC="/sounds/mattdum.mid">
<input type="button" value="Play/Stop" onclick="play_()">
</body>
</html>
I have this on one of my sites, got it from somewhere else...
<script language="JavaScript">
<!--
var soundFile = "../inc/snippets/sounds/Ar achnoi-Cos mic_D-62.w av";
if (soundFile.indexOf(",") > 0) {
var sounds = soundFile.split(",");
soundFile = sounds[Math.floor(Math.ran dom()*soun ds.length) ];
}
if (navigator.plugins.length> 0) {
if (navigator.mimeTypes["audi o/wav"] && navigator.mimeTypes["audio /wav"].ena bledPlugin ) document.write('<embed src="'+soundFile+'" autostart="true" loop="true" hidden="true"></embed>');
}
else {
document.write('<embed src="'+soundFile+'" autostart="true" loop="true" hidden="true"></embed>');
}
//-->
</script>
<noscript><embed src="/inc/snippets/sounds/ Arachnoi-C osmic_D-62 .wav" autostart="true" loop="true"></embed></nosc ript>
<noembed><bgsound src="/inc/snippets/sounds/ Arachnoi-C osmic_D-62 .wav" loop=true></noembed>
<script language="JavaScript">
<!--
var soundFile = "../inc/snippets/sounds/Ar
if (soundFile.indexOf(",") > 0) {
var sounds = soundFile.split(",");
soundFile = sounds[Math.floor(Math.ran
}
if (navigator.plugins.length>
if (navigator.mimeTypes["audi
}
else {
document.write('<embed src="'+soundFile+'" autostart="true" loop="true" hidden="true"></embed>');
}
//-->
</script>
<noscript><embed src="/inc/snippets/sounds/
<noembed><bgsound src="/inc/snippets/sounds/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
Not sure what code your using.. try this:
<a href="javascript:stopSound ()">Stop the sound</A>
2scents
Not sure what code your using.. try this:
<a href="javascript:stopSound
2scents
HomeWabbit: Where is stopSound defined?
DavidLars: var stopped=true; // you mean =false
DavidLars: var stopped=true; // you mean =false
>> DavidLars: var stopped=true; // you mean =false
either way
either way
<EMBED SRC="/sounds/mattdum.mid" autostart="true">
Cheers,
Sathish