简体   繁体   English

括号 p5.js 无法加载声音:错误“请求状态为:0 ()”

[英]Brackets p5.js won't load Sound: Error “The request status was: 0 ()”

My sound files won't load when I use the Live Preview within Brackets, the screen only shows "Loading..." and within the Console it states:当我在括号中使用实时预览时,我的声音文件不会加载,屏幕只显示“正在加载...”,并且在控制台中它指出:

The AudioContext was not allowed to start.不允许启动 AudioContext。 It must be resumed (or created) after a user gesture on the page.它必须在页面上的用户手势之后恢复(或创建)。 Unable to load assets/jump.wav.无法加载资产/jump.wav。 The request status was: 0 ()请求状态为:0 ()

This is my code:这是我的代码:

var jumpSound;

function preload()
{
    soundFormats('mp3','wav');
//    
    //load your sounds here
    jumpSound = loadSound('assets/jump.wav');
    jumpSound.setVolume(0.1);


}


function setup()
{
    createCanvas(1024, 576);
    floorPos_y = height * 3/4;
    lives = 3;
    
    startGame();
    jumpSound.play();

I tried changing my mp3's to wav and it worked for a bit but when I opened it up again later on it went back to the same error, so I know it's written correctly but it seems to be a technical issue with brackets or p5.js?我尝试将我的 mp3 更改为 wav,它工作了一段时间,但是当我稍后再次打开它时,它又回到了同样的错误,所以我知道它写得正确,但它似乎是括号或 p5.js 的技术问题? Any help would be appreciated thanks!任何帮助将不胜感激谢谢!

Wav is a bad idea for web audio, as wav files are huge compared to mp3 or ogg counterparts (I personally prefer ogg, as mp3 usually leaves a gap of silence in the beginning). Wav 对于 web 音频来说是个坏主意,因为 wav 文件与 mp3 或 ogg 对应的文件相比很大(我个人更喜欢 ogg,因为 mp3 通常在开始时会留下空白)。

Leaving that aside, some more context would be nice, like when you call the function.撇开这个不谈,更多的上下文会很好,比如当你调用 function 时。 I can recommend you to make a local server to host your program, that helped me with some problems loading files in the past.我可以建议您制作一个本地服务器来托管您的程序,这可以帮助我解决过去加载文件的一些问题。 An easy way to do this is using a chrome extension called 'Web server for chrome', in which you just select the folder where the index.html file is, and then it gives you a link you can open to run the file.一个简单的方法是使用一个名为“Chrome 的 Web 服务器”的 chrome 扩展程序,在其中您只需 select 文件夹,即 index.html 文件所在的文件夹,然后它会为您提供一个可以打开以运行该文件的链接。

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

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