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

Create multiple waveforms #2365

Closed
Raspberry42 opened this issue Sep 26, 2021 · 2 comments
Closed

Create multiple waveforms #2365

Raspberry42 opened this issue Sep 26, 2021 · 2 comments
Labels

Comments

@Raspberry42
Copy link

Raspberry42 commented Sep 26, 2021

Hello, I would like to create multiple waveforms.

Could someone tell me on why my code is not working?
Thanks.

<!DOCTYPE html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://unpkg.com/wavesurfer.js"></script>
</head>

<body>
    
    <div class="player d-flex justify-content-between">
        <div class="controls">
            <img src="play.png" alt="" id="play1">
        </div>
        <div id="waveform1"></div>
    </div>

    <div class="player d-flex justify-content-between">
        <div class="controls">
            <img src="play.png" alt="" id="play2">
        </div>
        <div id="waveform2"></div>
    </div>

    <script src="script.js"></script>
</body>
</html>
class waveForm 
{
    init(fileName, idWaveForm, idBtn) {
        var wavesurfer = WaveSurfer.create({
            container: idWaveForm,
            waveColor: '#000',
            progressColor: '#f2f2f2',
            cursorWidth: 1, 
            normalize: true,
            partialRender: true,
            responsive: true
        })
        
        wavesurfer.load(fileName)

        let playBtn = document.getElementById(idBtn)
        
        playBtn.onclick = function() {
            wavesurfer.playPause()
            playBtn.src.includes('play.png')? playBtn.src = 'pause.png': playBtn.src = 'play.png'
        } 
    }
}


let p1 = new waveForm()
p1.init('track1.mp3', '#waveform1','play1')

let p2 = new waveForm()
p2.init('track2.mp3', '#waveform2','play2')
@msuhov
Copy link
Contributor

msuhov commented Sep 27, 2021

Hi @Raspberry42

I did try your example in CodeSandbox - https://codesandbox.io/s/goofy-chandrasekhar-rrhqt?file=/src/index.js

Everything is working good there. Could it be problem with your audio files? Do you have any errors in console?

Thanks

@Raspberry42
Copy link
Author

Yes it works! Thank you.

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

3 participants