Guest User

Untitled

a guest
May 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class Player extends React.Component {
  2. constructor(props) {
  3. super(props);
  4. //I thought I would be able to control everything with props and states
  5. this.state = {playstate: this.props.playstate};
  6. this.handlePlay.bind(this);
  7. }
  8.  
  9. componentDidMount() {
  10. this.handlePlay();
  11. }
  12.  
  13. togglePlay() { //I don't understand how to reach this, or reproduce its behavior
  14. this.setState({ playstate: !this.state.playstate }, this.handlePlay);
  15. }
  16.  
  17. handlePlay() {
  18. if (this.state.playstate) this.refs.audio.play();
  19. else this.refs.audio.pause();
  20. }
  21.  
  22. render() {
  23. return (
  24. <audio className="audio-element" {...this.props} ref="audio"></audio>
  25. );
  26. }
  27. };
Add Comment
Please, Sign In to add comment