Skip to content

Instantly share code, notes, and snippets.

@Rassibassi
Created April 26, 2020 07:19
Show Gist options
  • Select an option

  • Save Rassibassi/768959b40d310faa437188097fc804d6 to your computer and use it in GitHub Desktop.

Select an option

Save Rassibassi/768959b40d310faa437188097fc804d6 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import WaveSurfer from 'wavesurfer.js';
class Waveform extends Component {
state = {
playing: false,
};
componentDidMount() {
this.waveform = WaveSurfer.create({
container: '#waveform',
scrollParent: true
});
this.waveform.load('https://www.mfiles.co.uk/mp3-downloads/gs-cd-track2.mp3');
};
handlePlay = () => {
this.setState({ playing: !this.state.playing });
this.waveform.playPause();
};
render() {
return (
<div>
<div id="waveform" />
<button onClick={this.handlePlay}>
{!this.state.playing ? 'Play' : 'Pause'}
</button>
</div>
);
}
};
export default Waveform;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment