Wavesurfer.js: How to reset canvas for wave

Created on 21 Nov 2017  路  1Comment  路  Source: katspaugh/wavesurfer.js

I am using wavesurfer and showing the wave in a modal. But when I close the modal and then want to open another file in new modal, it shows me the older wave. It looks like the canvas is not destroyed when I close the canvas.

I don't want to refresh the page under the modal. The canvas is destroyed obviously when I refresh the page.

Can you help?

question

Most helpful comment

@shaliniidea you can empty it and load another file when opening the modal:

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Load Audio</button>
<script>
$('#exampleModal').on('show.bs.modal', function (event) {
    wavesurfer.empty();
    wavesurfer.load('mp3link');
});
</script>

>All comments

@shaliniidea you can empty it and load another file when opening the modal:

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Load Audio</button>
<script>
$('#exampleModal').on('show.bs.modal', function (event) {
    wavesurfer.empty();
    wavesurfer.load('mp3link');
});
</script>
Was this page helpful?
0 / 5 - 0 ratings