简体   繁体   English

如何在 wavesurfer.js 中获取最新的 currentTime?

[英]How can i get the newest currentTime in wavesurfer.js?

I have problem.我有问题。 This code adds a click event to the wavebar.此代码将单击事件添加到波条。

wavesurfer.drawer.on("click", () => {console.log(wavesurfer.getCurrentTime())})

When i click on the wave bar, i get the time where the cursor was in!当我点击波浪条时,我得到了光标所在的时间! For example if the current time is 0 and i click on the wave bar and where i clicked on the wave bar is 3:03, i see that the log is 0!例如,如果当前时间为 0,并且我单击波形栏,而我单击波形栏的位置是 3:03,我看到日志为 0! But i want to get the latest time.但我想得到最新的时间。 In this example the latest time is 3:03 but 0 will be logged as the current time.在此示例中,最晚时间是 3:03,但 0 将被记录为当前时间。 an other example is when the current time is 3:00, and i move the cursor on where the time is 4:04, 3:00 will be logged and i dont want it.另一个例子是当当前时间是 3:00 时,我将光标移动到时间是 4:04 的地方,3:00 将被记录,我不想要它。 I want the time of where i moved the cursor.我想要我移动光标的时间。 I want 3:03 in example 1 and 4:04 in example 2. How can i solve this problem?我想要示例 1 中的 3:03 和示例 2 中的 4:04。我该如何解决这个问题? Thanks for helping.感谢您的帮助。

i fixed my problem.我解决了我的问题。 i wanted to get the time of where i clicked on.我想知道我点击的时间。 the event handler runs before the time gets update.事件处理程序在时间更新之前运行。 and in this situation, i should have a delay to get the time of where i clicked.在这种情况下,我应该有一个延迟来获得我点击的时间。 so i should use setTimeout method.所以我应该使用setTimeout方法。

wavesurfer.drawer.on("click", (e) => {
  setTimeout(() => {
    dispatch(musicSlice.updateMusicTime(wavesurfer.getCurrentTime()));
  }, 0);
});

if you want to know why i gave setTimeout 0 second of delay, please do a research about call stack , web apis and asynchronous in js and you'll understand why i gave 0 second of delay to setTimeout method.如果你想知道为什么我给 setTimeout 0 秒的延迟,请研究一下call stackweb apisasynchronous in js ,你就会明白为什么我给setTimeout方法延迟 0 秒。 i hope it helps you.我希望它可以帮助你。 good luck.祝你好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM