Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stopping propagation on click event for a Region to WaveForm #104

Open
BRIDGE-AI opened this issue Aug 20, 2024 · 5 comments
Open

stopping propagation on click event for a Region to WaveForm #104

BRIDGE-AI opened this issue Aug 20, 2024 · 5 comments

Comments

@BRIDGE-AI
Copy link

BRIDGE-AI commented Aug 20, 2024

This is basic structure, as I know.

  <WaveForm>
      {regions.map((regionProps) => (
          <Region
              onUpdateEnd={handleRegionUpdate}
              onClick={(region) => {
                  region.play();
              }}
              key={regionProps.id}
              {...regionProps}
          />
      ))}
  </WaveForm>

And I have a listener implementation for whole Wavesurfer instance like this.

        wavesurferRef.current.on("click", (progress) => {
            play(); // play the waveform from clicked time and to the end
        });

In this case, these 2 callbacks(onClick for region and the on("click") for the wavesurferRef) are all called.
The region event called first, and then wavesurfer click event called next.

I want to play all audio from clicked time when I clicked outside of all regions.
And I want to play only the region area when I clicked a region of all.

1. Is this code correct to catch on click for regions?
You have 'region-removed' event handler for region-removed on the example code below.

wavesurferRef.current.on("region-removed", (region) => {
console.log("region-removed --> ", region);
});

So, I thought 'region-click event could be possible.
The Wavesurfer is listing 'region-click' event in the reference. - https://wavesurfer.xyz/plugins/regions
But it's not working now.

        wavesurferRef.current.on("region-clicked", (region) => {
            console.log("region-click --> ", region);
        });

2. How can I modify this code when I want to stop propagating the event after called onClick() of regions and make on("click") has not called?

3. It seems that region.play() is playing all the audio from the time I clicked.
It is same to wavesurferRef.current.play().
Is this intended or a bug?

@BRIDGE-AI
Copy link
Author

Is anyone there?

@ShiiRochi
Copy link
Owner

ShiiRochi commented Sep 5, 2024

When you place on click on region you use special region event listener, wavesurfer listens for the whole waveform, thus you should decide on your own how to structure your application and how to use existing wavesurfer.js API.

If events are called in the same order, i.e. if region is called first and waveform's level listener is called next, then you can use some temporal variable to disable waveform's listener after region's is called.

@BRIDGE-AI
Copy link
Author

Thank you @ShiiRochi.
Okay for the event listener.

One more, how can I catch the time and stop the player when the region ends.

@ShiiRochi
Copy link
Owner

Thank you @ShiiRochi. Okay for the event listener.

One more, how can I catch the time and stop the player when the region ends.

Region has start and end...if wavesurfer does not stop playing on region end, then you can try to listen to "progress" event and when progress reaches the regions end, i.e. progress === region.end, then you can call pause method of wavesurfer or similar to stop playing but keeping cursor position.

Whatever you decide, try to reach wavesurfer.js documentation and check what ways you have because as far as I remember, previously wavesurfer played regions fine, however currently I don't have enough time to track all its changes.

@BRIDGE-AI
Copy link
Author

Thank you @ShiiRochi. Okay for the event listener.
One more, how can I catch the time and stop the player when the region ends.

Region has start and end...if wavesurfer does not stop playing on region end, then you can try to listen to "progress" event and when progress reaches the regions end, i.e. progress === region.end, then you can call pause method of wavesurfer or similar to stop playing but keeping cursor position.

Whatever you decide, try to reach wavesurfer.js documentation and check what ways you have because as far as I remember, previously wavesurfer played regions fine, however currently I don't have enough time to track all its changes.

thank you for your answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants