Wednesday, 11 September 2013

Making a html audio play/pause with javascript if else statement

Making a html audio play/pause with javascript if else statement

I've been looking for this answer for a few hours, I really appreciate
your help. I want to use javascript to make a button that plays and pauses
an audio file. I don't want to put any javascript in the html document.
From what I've read, jquery can't play audio, but javascript can. Is that
true?
Here's the html.
<audio id="player">
<source src="street.wav" type="audio/wav">
</audio>
<button id="playpause">Play</button>
And here's the javascript.
var audio=document.getElementById("#player");
audio.controls=false;
function togglePlayPause()
{
var playpause = document.getElementById("#playpause");
if (audio.pause()) {
audio.click.play();
}
else {
audio.click.pause();
}
}
Thank you for your help, I really appreciate it.

No comments:

Post a Comment