1

I was wondering how to make a play/pause button. Currently have it working, HTML and JS is in the answer.

will0956
  • 41
  • 1
  • 8
  • 1
    What's the question? I think if you're trying to do a self q&a, then you should reformat edit the question as a question and then post an answer – Jeff Puckett May 14 '16 at 20:02

1 Answers1

0

I used some other examples, and created this. Make sure that, if you use this, your HTML audio tag looks like this

<audio id="audio_core" autoplay="autoplay">
  <source src="audio/bgm.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

Here's the button itself:

<a href="javascript:void(0)" id="audiobutton" class="btn-floating btn-large waves-effect waves-light red" onclick="aud_play_pause()"><i id="icn" class="material-icons">pause</i></a>
<script>
function aud_play_pause() {
  var myAudio = document.getElementById("audio_core");
  if (myAudio.paused) {
    myAudio.play();
    $("#icn").text("pause");
  } else {
    myAudio.pause();
    $("#icn").text("play_arrow");
  }
}
</script>

Hope this helped!

will0956
  • 41
  • 1
  • 8