Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save alasomlira/95928a2aad457a8cc243e4a6905b455a to your computer and use it in GitHub Desktop.

Select an option

Save alasomlira/95928a2aad457a8cc243e4a6905b455a to your computer and use it in GitHub Desktop.
html5 audio player only play button
<a id="play-pause-button" class="fa fa-play"></a>
var audio = new Audio("http://www.stephaniequinn.com/Music/Allegro%20from%20Duet%20in%20C%20Major.mp3");
$('#play-pause-button').on("click",function(){
if($(this).hasClass('fa-play'))
{
$(this).removeClass('fa-play');
$(this).addClass('fa-pause');
audio.play();
}
else
{
$(this).removeClass('fa-pause');
$(this).addClass('fa-play');
audio.pause();
}
});
audio.onended = function() {
$("#play-pause-button").removeClass('fa-pause');
$("#play-pause-button").addClass('fa-play');
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
#play-pause-button{
font-size: 50px;
cursor: pointer;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment