1

I am creating a simulation page for an application. It requires a set of button controls to Play, Pause and Stop sample music. I read some questions on stackoverflow to get the controls working. Some questions that I referred were:

My problem starts when I set hidden="true" in embed tag and try to call javascript function. I have tried putting tag in a hidden div but it does not work.

Embed tag code:

<embed src="abc.mp3" AutoStart="false"  loop="false" height="0" width="0" hidden="true" />

Javascript to access embed tag methods.

document.embeds[0].Play();

cheers

Community
  • 1
  • 1
user11
  • 321
  • 2
  • 3
  • 12
  • Do you see any errors in the console? There is no function called `Play()`. It is spelled `play()`. – kmoser Sep 07 '21 at 03:00
  • Embed is now deprecated and only supported by browsers for compatibility of old websites, it might be removed from major browsers soon. To display a picture, it is better to use the tag. To display HTML, it is better to use the – ethry May 05 '22 at 21:02

2 Answers2

0

try Call play(), stop() script

<BGSOUND id="BGSOUND_ID" LOOP=1 SRC="jsilence.mid">

<script type="text/javascript" language="JavaScript">
<!--
function playSound(audioURL) {
 if (document.all) document.all['BGSOUND_ID'].src=audioURL;
 else self.iplayer.location.replace('jsplayer.htm?'+audioURL);
}

function stopSound() {
 if (document.all) document.all['BGSOUND_ID'].src='jsilence.mid';
 else self.iplayer.location.replace('jsplayer.htm?stop');
}
//-->
</script>

<form name=myform>
<input type=button value="Play Sound" onClick="playSound('Bach.mid')">
<input type=button value="Stop Sound" onClick="stopSound()">
</form>
Falguni Panchal
  • 8,873
  • 3
  • 27
  • 33
0

I've got two possible things that are making your code not working as expected:

  • What about if there is a previous embed in your document? I would set an id attribute for your audio and use document.getElementById("theId").play() instead of document.embeds[0].play()

  • Are you using Play() with capital P? Don't know if it's just a typo but could be also the error.

Hidden or visible it should work the same way,

hope it helps someone ;)

Hugo
  • 1,662
  • 18
  • 35