最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - "Uncaught (in promise) DOMException: Failed to load because no supported source was found" when p

programmeradmin6浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 3

Most 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论