<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title> Get Duration</title>
</head>
<body>
<h1>Get Duration of Audio file from URL in HTML</h1>
<audio id="audio-element">
<source src="http://labs.qnimate.com/files/mp3.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
<br>
<button onclick="duration();">Get Duration</button>
<p id="demo"></p>
<script type="text/javascript">
function duration()
{
var audio = document.getElementById("audio-element");
if(audio.readyState > 0)
{
var minutes = parseInt(audio.duration / 60, 10);
var seconds = parseInt(audio.duration % 60);
document.getElementById("demo").innerHTML="Duration - "+minutes+":"+seconds;
}
}
</script>
</body>
</html>
Download: Code
No comments:
Post a Comment