htmlcsscoding htmlcsscoding - 5 months ago 9
Javascript Question

Can someone show me how to add this code to the rest of the code

My Code: https://jsfiddle.net/7meetm89/1/

This is the code, I don't know how to add it to the rest of the code, can someone show me?

myaud=document.getElementById("player");myaud.volume=1.0;





<button style="cursor: pointer; background-color:blue;padding-bottom:1px;"
onclick="document.getElementById('player').play()">Play</button>

<audio id="player" preload="none" style="display:none;">
<source src='http://air.radiorecord.ru:8101/rr_320' type='audio/mpeg'/>
</audio>

Answer

Add one function() on onclick. Set volume and play controls inside that function.

Additional Changes: Added controls in audio tag to display HTML5 controls and removed display:none

Edit: You can add setControls() function inside <script> </script> tag. You can also add script in external file and link it. Please read more

function setControls() {
    myaud=document.getElementById("player");
    myaud.play();
    myaud.volume=1.0;
  }
<button style="cursor: pointer; background-color:blue;padding-bottom:1px;"
onclick="setControls()">Play</button>

<audio controls id="player" preload="none">
<source src='http://air.radiorecord.ru:8101/rr_320' type='audio/mpeg'/>
</audio>