-
-
Save maheshbabu/1817139 to your computer and use it in GitHub Desktop.
Retrieve the duration of an HTML5 audio element.
This file contains 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html> | |
<head> | |
<title>HTML5 Audio Duration</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<script type="text/javascript"> | |
var audio, duration; | |
window.onload = function() { | |
var element = document.createElement("audio"); | |
element.setAttribute("id", "audio"); | |
element.setAttribute("src", "http://watoo.net:8000/INTRODUCTION.mp3"); | |
document.getElementsByTagName("body")[0].appendChild(element); | |
getDuration(); | |
}; | |
function getDuration() { | |
audio = document.getElementById("audio"); | |
audio.addEventListener("loadedmetadata", function(_event) { | |
duration = audio.duration; | |
document.getElementsByTagName("body")[0].removeChild(audio); | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment