javascript - How to get the played time from HTML5 audio player? - Stack Overflow

Consider a simple `HTML5 audio player as (live example)<audio controls><source src=".flac

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
Add a ment  | 

2 Answers 2

Reset to default 4

Use 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信