-1

I am writing a code in Framer x which uses Javascript and react library.

I would like to make different sounds depending on the coordinate values of for instance mouse ( x, y, and z ). How can I play an mp3 file in an if condition, e.g., if x>10 --> play drum1.mp3 if 10>x>20 --> play drum2.mp3?

I would be grateful if someone can help me with this.

Thanks.

ansar
  • 1

1 Answers1

0
function playAudio (filePath) {
  const audio = new Audio(filePath);
  audio.play();
}

if (x > 10) {
  playAudio('drum1.mp3')
} else if (x < 10 && x > 20) {
  playAudio('drum2.mp3')
}
tarzen chugh
  • 10,561
  • 4
  • 20
  • 30