简体   繁体   English

播放带有特殊字符的音频时,“(未承诺)DOMException:未能加载,因为找不到支持的源”

[英]“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.

相关问题 在 Vue 中播放声音 onClick 事件返回 Uncaught (in promise) DOMException: Failed to load because no supported source was found - playing sound onClick event in Vue returns Uncaught (in promise) DOMException: Failed to load because no supported source was found Chrome:未捕获(承诺)DOMException:无法加载,因为找不到支持的源 - Chrome: Uncaught (in promise) DOMException: Failed to load because no supported source was found Android Chrome:未捕获(承诺)DOMException:由于找不到受支持的源而无法加载 - Android Chrome : Uncaught (in promise) DOMException: Failed to load because no supported source was found 无法加载音频 - DOMException:无法加载,因为找不到支持的源 - Cant load Audio - DOMException: Failed to load because no supported source was found DOMException:加载失败,因为未找到支持的源 - DOMException: Failed to load because no supported source was found 加载失败,因为找不到支持的源 - Failed to load because no supported source was found 以blob为源播放音频时出现DOMException - DOMException when playing audio with blob as source 播放 AUDIO 时 Google Chrome Uncaught (in promise) DOMException - Google Chrome Uncaught (in promise) DOMException while playing AUDIO 音频播放器返回 Uncaught (In promise): (DOMException) 该元素没有支持的源 - Audio player returns Uncaught (In promise): (DOMException) The element has no supported sources Phonegap视频“由于找不到支持的来源而无法加载” - Phonegap Video “Failed to load because no supported source was found”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM