- Forums
- react
- React Play Audio Component For React Application Mp3 Button
This a component I used to play mp3 audio files in my react applications [5303], Last Updated: Mon Jun 24, 2024
edw
Tue Apr 02, 2024
0 Comments
193 Visits
This a component I used to play mp3 audio files in my react applications.
you can call this function with a play button.
Source: /g/SCHOOL/Apps/2022/84-words-kinder
const playAudio = (word) => {
//alert(word)
// also available: https://ssl.gstatic.com/dictionary/static/sounds/20200429/teacher--_us_1.mp3 from google
let audio = new Audio(`https://www.websor.com/pre-school/words/84words/sounds/?w=${word}`)
//https://stackoverflow.com/questions/16077642/javascript-html5-audio-dont-play-sound-if-already-playing
if (!playingAudio) {
playingAudio = true;
setTimeout(() => {
playingAudio = false;
audio.play();
}, 100);
}
}