简体   繁体   中英

Play an mp3 file in a if condition

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, eg, 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.

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')
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM