简体   繁体   English

如何防止 Wavesurfer.js 通过单击波形停止播放?

[英]How to prevent Wavesurfer.js stopping playback with click on waveform?

I have a wavesurfer player ( https://wavesurfer-js.org/ ) with (a working) play/pause-Button and waveform.我有一个 wavesurfer 播放器 ( https://wavesurfer-js.org/ ) 与(一个工作)播放/暂停按钮和波形。 Goal: a click on the waveform continues playback from the new position, if player is running.目标:如果播放器正在运行,单击波形会继续从新的 position 播放。 Right now a click on the waveform of the running player causes the player to pause.现在,单击正在运行的播放器的波形会导致播放器暂停。 The progress is moved correctly to the new position and a hit on the play-button starts the playback from there.进度被正确地移动到新的 position 并且点击播放按钮从那里开始播放。 I can capture the (undocumented by wavesurfer) click-event我可以捕获(wavesurfer 未记录的)点击事件

myWaveSurfer.drawer.on('click', e => {
      myWaveSurfer.play();
    });

but this does not seem to do the trick.但这似乎并不能解决问题。 I already tried e.preventDefault() .我已经尝试过e.preventDefault() Any ideas are greatly appreciated.非常感谢任何想法。

My guess is that this is related to the bug that was introduced in version 4.2 ( issue on Github ).我的猜测是这与版本 4.2 中引入的错误有关( Github 上的问题)。 Version 4.4 is supposed to include a fix, so I'd suggest updating or reverting to 4.1. 4.4 版应该包含一个修复程序,所以我建议更新或恢复到 4.1。

If updating is not an option, simply calling play() on the seek event seems to work even though isPlaying() returns true already.如果更新不是一个选项,即使isPlaying()已经返回 true,简单地调用seek事件上的play()似乎也有效。 It feels a bit hacky since it's not the intended behavior, but here's an example:感觉有点老套,因为这不是预期的行为,但这是一个例子:

wavesurfer.on('seek', () => {
  if (wavesurfer.isPlaying()) {
    wavesurfer.play();
  }
});

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

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