DEV Community

aleksjy
aleksjy

Posted on

button audio

Good afternoon. I have a react app.
There are fifty audio buttons on the page.
Each button has its own small mp3 file.
I can't find the correct code to write such a page. Perhaps there are solutions. Share the link please)

Top comments (2)

Collapse
 
aleksjy profile image
aleksjy

Thanks for your attention and reply.
How to import { new audio }
I still can't find a working solution.
There is a lot of code and complexity everywhere.
Image description
Image description

Collapse
 
tanimu_maidoki profile image
Umar Maidoki • Edited

You can try the if else()

const music = new audio("https://usic.mp3")
if(music.paused) {
    music.play()
}else {
   music.pause()
}
Enter fullscreen mode Exit fullscreen mode

Add this to onClick function