I’m regretfully a total noob to html so I was hoping you could answer my question.
I’m trying to implement three audio files on my webpage but only one of the source files is playing. The buttons for the other files work, but they only play from the one source. Can you help me?
Here’s the code:
<div class="sound1">
<div style="text-align:center; width:100px; height:100px; margin-left:390px; margin-top:0px; background-repeat:no-repeat; ">
<button style="background-image:url(speaker_bakur.png); width:100px; height:100px; border:transparent;
; "margin-top:0px; margin-left:0px;" onclick="playPause();" ></button>
<audio id="Sound">
<source src="" type="audio/wav" />
<source src="" type="audio/ogg" />
<source src="svartbakur-4.mp3" type="audio/mpeg" />
</audio>
</div>
<script type="text/javascript">
var myAudio=document.getElementById("Sound");
function playPause()
{
if (myAudio.paused)
myAudio.play();
else
myAudio.pause();
}
</script>
</div>
</div><!--Div hyphenate-->
<div class="sound2">
<div style="text-align:center; width:100px; height:100px; margin-left:390px; margin-top:0px; background-repeat:no-repeat; ">
<button style="background-image:url(speaker_likka.png); width:100px; height:100px; border:transparent;
; "margin-top:0px; margin-left:0px;" onclick="playPause();" ></button>
<audio id="Sound">
<source src="" type="audio/wav" />
<source src="" type="audio/ogg" />
<source src="likka-6.mp3" type="audio/mpeg" />
</audio>
</div>
<script type="text/javascript">
var myAudio=document.getElementById("Sound");
function playPause()
{
if (myAudio.paused)
myAudio.play();
else
myAudio.pause();
}
</script>
</div>
</div><!--Div hyphenate-->
<div class="sound3">
<div style="text-align:center; width:100px; height:100px; margin-left:390px; margin-top:0px; background-repeat:no-repeat; ">
<button style="background-image:url(speaker_fiskimasi.png); width:100px; height:100px; border:transparent;
; "margin-top:0px; margin-left:0px;" onclick="playPause();" ></button>
<audio id="Sound">
<source src="" type="audio/wav" />
<source src="" type="audio/ogg" />
<source src="fiskimasi-21.mp3" type="audio/mpeg" />
</audio>
</div>
<script type="text/javascript">
var myAudio=document.getElementById("Sound");
function playPause()
{
if (myAudio.paused)
myAudio.play();
else
myAudio.pause();
}
</script>
</div>
</div><!--Div hyphenate-->
Thank you so much!
Here is how to play the multiple audio from one single JavaScript function: