Rinkusu – 22-42 Jan 5

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()
}
G
ghardin137834d ago
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
L
LaRynk834d ago
google chrome I used to play mp3 sounds in chrome with react projects the path is 100% good
G
ghardin137834d ago
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
L
LaRynk834d ago
G
ghardin137834d ago
../assets/hihat.mp3 is probably not the right path in the browser even though it is in your file system
L
LaRynk834d ago
i see
G
ghardin137834d ago
for example http://localhost:3000/../assets/hihat.mp3 wouldn't work properly
L
LaRynk834d ago
so where do I find this path ? for the browser
G
ghardin137834d ago
well it depends on where your webroot is i'm guessing thats that dist folder?
L
LaRynk834d ago
it is ! thx
G
ghardin137834d ago
ok. so then your assets folder would need to be inside dis dist
L
LaRynk834d ago
yep
G
ghardin137834d ago
and then you'd do /assets/hihat.mp3
UU
Unknown User833d ago