Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import React from "react";
  2. import "./App.css";
  3. import pig from "./img/pig.jpg";
  4. import pigsound1 from "./music/1.mp4";
  5. import pigsound2 from "./music/2.mp4";
  6. import pigsound3 from "./music/3.mp4";
  7. // import MIDISounds from "midi-sounds-react";
  8.  
  9. const musicButton = [pigsound1, pigsound2, pigsound3];
  10. let soundNumber = 1;
  11. class App extends React.Component {
  12. state = {
  13. music: musicButton,
  14. sound: soundNumber
  15. };
  16.  
  17. onClick = e => {
  18. console.log(this.state.sound);
  19. this.state.sound = Math.floor(Math.random() * this.state.music.length);
  20. console.log(this.state.sound);
  21. if (this.audio) {
  22. this.audio.pause();
  23. }
  24. this.audio = new Audio(e.target.dataset.url);
  25. this.audio.play();
  26. console.log(this.state.music[`${this.state.sound}`]);
  27. };
  28.  
  29. render() {
  30. return (
  31. <div className="App-header">
  32. <img src={pig} />
  33. {/* {.this.state.music.map(n => ( */}
  34. <button
  35. onClick={this.onClick}
  36. data-url={this.state.music[`${this.state.sound}`]}
  37. key={this.state.sound}
  38. >
  39. Где свиньи?
  40. </button>
  41. </div>
  42. );
  43. }
  44. }
  45. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement