Consider a simple `HTML5 audio player as (live example)
<audio controls>
<source src=".flac" type="audio/flac">
</audio>
<br />
<dic class="capture">
Click here to get the current played time (elapsed time)
</dic>
Can we create a javascript event to catch the elapsed time of the playing audio by clicking on an HTML element?
Consider a simple `HTML5 audio player as (live example)
<audio controls>
<source src="https://hpr.dogphilosophy/test/flac.flac" type="audio/flac">
</audio>
<br />
<dic class="capture">
Click here to get the current played time (elapsed time)
</dic>
Can we create a javascript event to catch the elapsed time of the playing audio by clicking on an HTML element?
Share Improve this question asked Feb 21, 2018 at 14:43 GooglebotGooglebot 15.7k45 gold badges144 silver badges247 bronze badges 1- Possible duplicate of html5 display audio currentTime – JJJ Commented Feb 21, 2018 at 14:49
2 Answers
Reset to default 4Use currentTime to get the current timestamp, e.g.:
var audio = document.getElementById("audio-element");
document.getElementById('capture').addEventListener('click', () => {
console.log(audio.currentTime);
});
<audio id="audio-element" controls>
<source src="https://hpr.dogphilosophy/test/flac.flac" type="audio/flac">
</audio>
<br />
<button id="capture">
Click here to get the current played time
</button>
I believe HTML audio has a built in currentTime property that you could use to get the point in the audio where you're currently at:
https://www.w3schools./tags/av_prop_currenttime.asp
Is this what you're looking for?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745388717a4625560.html
评论列表(0条)