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

Using bars with ZoomPlugin causes terrible zoom performance in non-chrome browsers #3864

Open
jaredgei opened this issue Sep 10, 2024 · 1 comment
Labels

Comments

@jaredgei
Copy link

jaredgei commented Sep 10, 2024

Bug description

I have barWidth set to 2 and barGap set to 1. When I use this setup with the ZoomPlugin, I get terrible zooming performance in Safari on my mac. I'm just zooming using the default mousewheel input using the trackpad on my mac, I don't have any additional slider created. When I remove barWidth and barGap, zoom performance is perfect. The more bars are onscreen, the worse this gets. Perhaps zoom could have a debounce option or use requestAnimationFrame so it re-renders less often? I'm using @wavesurfer/react if that makes a difference.

Environment

  • Browser: Safari

Minimal code snippet

        <WavesurferPlayer
          url={audio}
          backend='WebAudio'
          waveColor='#0853aa'
          progressColor='#0853aa'
          cursorColor='#111111'
          cursorWidth={2}
          barWidth={2}
          barGap={1}
          height={200}
          onReady={(wavesurfer: any) => setWavesurfer(wavesurfer)}
          onPlay={() => setPlaying(true)}
          onPause={() => setPlaying(false)} />

I'm registering ZoomPlugin like this, not sure if there's a better way to do it:

    if (!zoomPlugin.current) {
      zoomPlugin.current = ZoomPlugin.create();
      wavesurfer.registerPlugin(zoomPlugin.current);
    }
@jaredgei jaredgei added the bug label Sep 10, 2024
@jaredgei
Copy link
Author

Small update but I tried this without @wavesurfer/react and I'm getting the same behavior, so it's definitely not a react specific issue. Here's my code.

  useEffect(() => {
    regionsPlugin.current = RegionsPlugin.create();
    zoomPlugin.current = ZoomPlugin.create();

    wavesurfer.current = Wavesurfer.create({
      container: annotationPlayer.current,
      url: audio,
      backend: 'WebAudio',
      waveColor: '#0853aa',
      progressColor: '#0853aa',
      cursorColor: '#111111',
      cursorWidth: 2,
      barWidth: 2,
      barGap: 1,
      height: 200,
      plugins: [zoomPlugin.current, regionsPlugin.current]
    });

    wavesurfer.current.on('ready', () => setLoading(false));
    wavesurfer.current.on('play', () => setPlaying(true));
    wavesurfer.current.on('pause', () => setPlaying(false));

    regionsPlugin.current.enableDragSelection({ color: 'rgba(8, 83, 170, 0.1)' });
    regionsPlugin.current.on('region-updated', onRegionsChanged);
    regionsPlugin.current.on('region-created', onRegionsChanged);
    regionsPlugin.current.on('region-removed', onRegionsChanged);

    return () => {
      regionsPlugin.current.un('region-updated', onRegionsChanged);
      regionsPlugin.current.un('region-created', onRegionsChanged);
      regionsPlugin.current.un('region-removed', onRegionsChanged);
      wavesurfer.current.un('play', () => setPlaying(true));
      wavesurfer.current.un('pause', () => setPlaying(false));
      wavesurfer.current.destroy();
    };
  }, []);

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

No branches or pull requests

1 participant