AudioPlayer.js 642 B

12345678910111213141516171819202122232425262728293031323334353637
  1. class AudioPlayer extends GameObject
  2. {
  3. constructor(name, p5Audio = null)
  4. {
  5. super(name);
  6. this.p5Audio = p5Audio;
  7. }
  8. setP5Audio(p5Audio)
  9. {
  10. if (this.p5Audio) this.p5Audio.stop();
  11. this.p5Audio = p5Audio;
  12. }
  13. getP5Audio()
  14. {
  15. return this.p5Audio;
  16. }
  17. play()
  18. {
  19. if (this.p5Audio) this.p5Audio.play();
  20. }
  21. stop()
  22. {
  23. if (this.p5Audio) this.p5Audio.stop();
  24. }
  25. // TODO: This don't worky, make it worky
  26. // Something to do with new browser audio policy
  27. autoplay()
  28. {
  29. if (this.p5Audio) this.p5Audio.autoplay(true);
  30. }
  31. }