Created
July 17, 2018 02:20
-
-
Save Sterv/3a245dbe316cbb2cedb85a84d4d1b979 to your computer and use it in GitHub Desktop.
Player demo
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 Tone from 'tone'; | |
| class Player extends Component { | |
| constructor(props){ | |
| super(props); | |
| this.state = { | |
| isLoadingAudioPlayer: false | |
| } | |
| } | |
| componentWillMount () { | |
| const { playbackRate, drumLoop } = this.props; | |
| var player = new Tone.Player(drumLoop, onPlayerLoad).toMaster(); | |
| player.playbackRate = playbackRate; | |
| window.players[playbackRate] = player; | |
| this.setState({ | |
| player, | |
| }); | |
| function onPlayerLoad (){ | |
| this.setState({ | |
| isLoadingAudioPlayer: true, | |
| }); | |
| } | |
| } | |
| handleClick () { | |
| this.state.player.start(); | |
| } | |
| render() { | |
| const { index, playbackRate, inheritedStyle } = this.props; | |
| if (this.state.isLoadingAudioPlayer){ | |
| return ( | |
| <div> | |
| Loading audio player... | |
| </div> | |
| ); | |
| } | |
| return ( | |
| <div> | |
| <button style={inheritedStyle} onClick={this.handleClick.bind(this)}>start player with playbackRate set to {playbackRate}</button> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default Player; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment