简体   繁体   English

无法获取音频文件

[英]Can't get the audio file

I want to play audio using this code: 我想使用以下代码播放音频:

var audio = new Audio("Assets/Tune/A#.mp3")

but the error is GET file:///C:/Users/user/Desktop/PROYEK/Assets/Tune/A net::ERR_FILE_NOT_FOUND 但是错误是GET file:///C:/Users/user/Desktop/PROYEK/Assets/Tune/A net::ERR_FILE_NOT_FOUND

while I can play the audio in this code: 虽然我可以在这段代码中播放音频:

var audio = new Audio("Assets/Tune/A''.mp3");

how to fix this ? 如何解决? Thanks 谢谢

In a URL the character # indicates the end of the local path (or query string) and start of the fragment identifier. 在URL中,字符#表示本地路径(或查询字符串)的结尾和片段标识符的开头。

If you want to use it in the local path you need to express it as %23 . 如果要在本地路径中使用它,则需要将其表示为%23

# is understood as an anchor and disregarded when retrieving the file. #被理解为锚,并且在检索文件时被忽略。 You may try to urlencode it (transforming it into %23 ) or as other suggested renaming your file. 您可以尝试对它进行urlencode(将其转换为%23 ),或者如其他建议那样重命名文件。

var audio = new Audio("~/Assets/Tune/A.mp3");

~ tells the roor directory. 〜告诉roor目录。 and give proper name to the file. 并给文件起适当的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM