Wavesurfer.js: Song not loaded when providing peaks

Created on 18 Jul 2018  路  9Comments  路  Source: katspaugh/wavesurfer.js

Hey, I recently switch my project to server side generated waveform and it brings me a bug.
When peaks aren't provided, the 'ready' event fires when i call wavesurfer.load(url).
However, when peaks are provided, the 'ready' event isn't fired, and the song isn't loaded until I use play function or interact with the waveform.
So I tried to understand why, and I found this. When peaks are provided, it loads the song only when 'interact' event is fired.

https://github.com/katspaugh/wavesurfer.js/blob/00b1e8185c9987ebaa950188b9bc060b31967626/src/wavesurfer.js#L1236

Shouldn't we replace this line by just a return load(); ?

bug

Most helpful comment

Hey !

Could you please explain a bit more on how to use your workaround?

The workaround is meant to replace only the load function, so usage is the same.

Do I still need to call the provided wavesurfer.load function?

No

However the values of the waveform became wrong

Please make sure that the data you are providing is well formated. I've made a simple wrapper that output correct data if you want: https://github.com/Guisch/simpleWaveformJs

All 9 comments

Is this going to be fixed anytime soon? Is there a workaround for now?

Made this workaround, works fine for me

function load(url, peaks) {
    wavesurfer.backend.setPeaks(peaks);
    wavesurfer.drawBuffer();
    wavesurfer.getArrayBuffer(url, data => wavesurfer.loadArrayBuffer(data));
}

Looks like duplicate of #1244

hi @Guisch , with your workaround I managed to fire waveform-ready event when providing peaks. However the values of the waveform became wrong. Could you please explain a bit more on how to use your workaround? Do I still need to call the provided wavesurfer.load function?

Thanks for sharing your workaround.

Hey !

Could you please explain a bit more on how to use your workaround?

The workaround is meant to replace only the load function, so usage is the same.

Do I still need to call the provided wavesurfer.load function?

No

However the values of the waveform became wrong

Please make sure that the data you are providing is well formated. I've made a simple wrapper that output correct data if you want: https://github.com/Guisch/simpleWaveformJs

Thank you very much for your response. The wrapper seems really useful as well, so thanks for that too! @Guisch

@Guisch that looks like a useful tool. maybe we can include it in wavesurfer.js so more people can help maintain it and use it?

I need to do some edit first but Yeah why not

Awesome, looking forward to the PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Trojan0523 picture Trojan0523  路  3Comments

thijstriemstra picture thijstriemstra  路  5Comments

SGDAT picture SGDAT  路  3Comments

Gerlie15 picture Gerlie15  路  4Comments

CramericaIndustries picture CramericaIndustries  路  4Comments