[英]“Uncaught (in promise) DOMException: Failed to load because no supported source was found” when playing an audio with special characters
I'm playing some audios from a folder in my page, and most of them play without any issues, but when it comes to play a file with a name like "jär" i get this error: 我正在播放页面中某个文件夹中的一些音频,并且大多数音频播放都没有任何问题,但是播放名称为“jär”之类的文件时出现此错误:
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. 我不知道是否与网络浏览器有关,我在Chrome上运行项目。 I'm using JavaScript and JQuery 我正在使用JavaScript和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. 非常感谢。
Most likely what's happening is that your browser isn't resolving URLs with Unicode characters. 最有可能的情况是您的浏览器无法解析带有Unicode字符的URL。 When pulling your media files, try wrapping it in a encodeURIComponent()
. 拉取媒体文件时,请尝试将其包装在encodeURIComponent()
。 This will format the URI according to the proper conventions, using percent encoding for special characters. 这将根据特殊约定对URI进行格式化,对特殊字符使用百分比编码。 For example, jär
becomes j%C3%A4r
. 例如, jär
变为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: 只是想让您知道我终于解决了我的问题,似乎我不得不在ISO 8859上对值进行编码,所以我要做的就是将值包装在一个转义子句中,例如:
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. 我希望此解决方案对其他遇到此问题的人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.