I'm playing some audios from a folder in my page, and most of them play without any issues, but when it es to play a file with a name like "jär" i get this error:
Uncaught (in promise) DOMException: Failed to load because no supported source was found.
I don´t know if it has something to do with my web browser, I run my project on Chrome. I'm using JavaScript and JQuery
The error happens only with files that have some kind of accent or special character on its name (like ä). What I wanna do is, of course, to play such audio regardless its name. Any help is appreciated. Thank you so much.
I'm playing some audios from a folder in my page, and most of them play without any issues, but when it es to play a file with a name like "jär" i get this error:
Uncaught (in promise) DOMException: Failed to load because no supported source was found.
I don´t know if it has something to do with my web browser, I run my project on Chrome. I'm using JavaScript and JQuery
The error happens only with files that have some kind of accent or special character on its name (like ä). What I wanna do is, of course, to play such audio regardless its name. Any help is appreciated. Thank you so much.
Share Improve this question asked Jul 22, 2017 at 5:52 litanedlitaned 671 silver badge7 bronze badges2 Answers
Reset to default 3Most likely what's happening is that your browser isn't resolving URLs with Unicode characters. When pulling your media files, try wrapping it in a encodeURIComponent()
. This will format the URI according to the proper conventions, using percent encoding for special characters. For example, jär
bees j%C3%A4r
.
x = 'jär'
console.log(x)
console.log(encodeURIComponent(x))
Just wanted to let you know that I finally solved my problem, it seemed I had to encode the value on ISO 8859, so all I had to do was to wrap the value in an escape clause like:
var encode = escape("jär")
And that's it. It worked like a charm. I hope this solution helps to any other who has this issue.