bbc / peaks.js

JavaScript UI component for interacting with audio waveforms
https://waveform.prototyping.bbc.co.uk
GNU Lesser General Public License v3.0
3.2k stars 279 forks source link

Event when scroll occurs during playback? #343

Open larrywal opened 3 years ago

larrywal commented 3 years ago

If I play a song and the current time in playback exceeds what's shown in the zoomed waveform, the waveform scrolls forward to keep the current time visible.

Is there a way to get an event when that happens?

chrisn commented 3 years ago

There is already a zoomview.displaying event that gives you the start and end time when the waveform view scrolls (either automatically or if the user drags the view). This is an implementation detail, so not part of the Peaks.js API - I will probably rename this event if we want to make it part of the API.

larrywal commented 3 years ago

Thanks much @chrisn - tried to hook it like I did other events but there's no TypeScript definition for it. Also, it seems to fire a ton - like even if I'm just hovering over it. Do you have a small example typescript code that shows its use?

Not sure (need to play more) but when I directly set the view using a function (e.g. setZoom) I think the event may be firing. Is that possible?

chrisn commented 3 years ago

OK, so that event may not be what you need. Do you need an event for when the displayed time region changes for any reason, not just the automatic update during playback? For example, also on changing zoom level, or when user drags to scroll the view?

larrywal commented 3 years ago

Ideally yes. I have a separate timeline control and I'm trying to keep the exact zoom / viewport sync'd between that control and this.

chrisn commented 3 years ago

Peaks.js uses the zoomview.displaying event to sync its own viewport display in the overview waveform (the lower waveform in demo/index.html). The event doesn't fire on hovering, only when the waveform viewport changes. Can you explain more about it firing too much?

I can see two minor problems with using this event:

Peaks.init(options, (err, peaks) => {
  peaks.on('zoomview.displaying', (start, end) => { ... });
});