R
Reactiflux

Rinkusu – 22-42 Jan 5

Rinkusu – 22-42 Jan 5

LLaRynk1/5/2022
hi, "DOMException: The element has no supported sources." for audio playing, help please
let hihatSound = new Audio('hihat.mp3')

let hihatBtn = document.getElementById('hi-hat').addEventListener('click', e => { play('hihat') })

function play (instru) {
console.log('play', instru)

instru === 'hihat' && hihatSound.play()
}
let hihatSound = new Audio('hihat.mp3')

let hihatBtn = document.getElementById('hi-hat').addEventListener('click', e => { play('hihat') })

function play (instru) {
console.log('play', instru)

instru === 'hihat' && hihatSound.play()
}
Gghardin1371/5/2022
that means either you haven't finished loading the file or the file wasn't found where you told it to look or potentially you're trying to play a file in a browser that doesn't support an mp3
LLaRynk1/5/2022
google chrome I used to play mp3 sounds in chrome with react projects the path is 100% good
Gghardin1371/5/2022
right now it's trying to load it from the current path you're on so if you're on like /blah it's gonna try to load it from /blah/hihat.mp3 check your network tab in the devtools
LLaRynk1/5/2022
Gghardin1371/5/2022
../assets/hihat.mp3 is probably not the right path in the browser even though it is in your file system
LLaRynk1/5/2022
i see
Gghardin1371/5/2022
for example http://localhost:3000/../assets/hihat.mp3 wouldn't work properly
LLaRynk1/5/2022
so where do I find this path ? for the browser
Gghardin1371/5/2022
well it depends on where your webroot is i'm guessing thats that dist folder?
LLaRynk1/5/2022
it is ! thx
Gghardin1371/5/2022
ok. so then your assets folder would need to be inside dis dist
LLaRynk1/5/2022
yep
Gghardin1371/5/2022
and then you'd do /assets/hihat.mp3
UUUnknown User1/6/2022
Message Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

Rinkusu – 22-42 Jan 5

Join Server