Created
April 26, 2020 07:19
-
-
Save Rassibassi/768959b40d310faa437188097fc804d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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