katspaugh / wavesurfer.js

Audio waveform player
https://wavesurfer.xyz
BSD 3-Clause "New" or "Revised" License
8.66k stars 1.62k forks source link

seekTo does not scroll waveform #3181

Closed jgentes closed 1 year ago

jgentes commented 1 year ago

Bug description

Using waveform.seekTo(.5) should scroll the waveform to the 50% position, but it doesn't :(

Environment

Minimal code snippet

Add wavesurfer.seekTo(.5) to the end of this example: https://wavesurfer-js.org/examples/?zoom.js

I've also tried including autoScroll: true and autoCenter: true as options

Expected result

Zoom view should move to half way point in the waveform

Obtained result

It stays at zero

Screenshots

katspaugh commented 1 year ago

This method requires that the audio is already loaded. If you’d like it to jump to the middle as soon as possible, you could subscribe to the ready event. I’ve just tested and it does work if you add it not to the bottom of that example but on a button click.

jgentes commented 1 year ago

Thanks, in my code I do have it firing after the 'ready' event, and it has been giving me trouble all morning, but retesting it now it's working for some reason. I recently moved to Cloudflare Pages and the Workers local dev setup feels like it has some oddities that cause wierd behavior.

Anyway, thanks for looking at it, I think we're good. :)

jgentes commented 1 year ago

I've reproduced it, it's related to the width of the browser. If it's too narrow, it fires another scroll event:

Scroll 60.266982064470696s 65.53011707565867s
Scroll 60.266982064470696s 65.53011707565867s
Scroll 0.020002413642241448s 5.2831374248301985s

The third Scroll log only occurs with a narrow browser window..

But I can't reproduce this on your demo page, so I'll keep digging.

jgentes commented 1 year ago

Ok, it's reproducible using wavesurfer.on('ready', () => wavesurfer.seekTo(.5)) - if you resize the browser window by any amount, it goes back to zero.

So maybe this should be listening for a different event rather than ready?

jgentes commented 1 year ago

Yep, this works perfectly: wavesurfer.on('redraw', () => wavesurfer.seekTo(.5))

bernardwiesner commented 8 months ago

@katspaugh Before upgrading to v7 I could use seekTo without loading audio:

surfer.load('', wave, duration)

However now seekTo does not work anymore when audio is not loaded. Is it possible to restore the previous behavior? I am not using wavesurfer for playback only for rendering.

katspaugh commented 8 months ago

@bernardwiesner as mentioned here, you can achieve that by adding backend: 'WebAudio' to the options.