Created
September 15, 2015 20:09
-
-
Save dmcclory/af562e282736a668c86d to your computer and use it in GitHub Desktop.
Javascript control of audio elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> | |
</head> | |
<body> | |
<h1>Yo a Podcast episode!</h1> | |
<audio controls src="http://traffic.libsyn.com/ucblongform/Karin_Louise_Hammerberg.mp3" type="audio/mpe | |
g"> | |
Your browser does not support the <code>audio</code> element. | |
</audio> | |
<button id="jump-back"> | |
Jump back 20 seconds | |
</button> | |
<button id="jump-ahead"> | |
Jump ahead 20 seconds | |
</button> | |
<button id="double-rate"> | |
Double Playback Rate | |
</button> | |
<script> | |
$("button#jump-ahead").click(function() { | |
$('audio')[0].currentTime += 20; | |
}); | |
$("button#jump-back").click(function() { | |
$('audio')[0].currentTime -= 20; | |
}); | |
$("button#double-rate").click(function() { | |
audio = $('audio')[0]; | |
if (audio.playbackRate == 1) { | |
audio.playbackRate = 2; | |
} else { | |
audio.playbackRate = 1; | |
} | |
}); | |
mediaReport = function() { | |
x = $('audio')[0]; | |
console.log(x.played.end(0)); | |
console.log(x.played.start(0)); | |
} | |
setInterval(mediaReport, 5000); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment