We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm a big fan of Processing and I'm psyched about p5. The visual stuff is working great, but I'm having a problem with the most basic sound stuff. I copied the first example from the p5 sound page and put a sound file in my assets folder. When I run the page locally, I get the error at the end of the message. Any ideas what I'm doing wrong?
Thanks! Peter Farrell
p5.sound.js:674 XMLHttpRequest cannot load file:///C:/Users/Peter/Desktop/peterf/js/p5/assets/bulgaria.mp3. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
p5.sound.js:682 size unknown
p5.sound.js:674 Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/Users/Peter/Desktop/peterf/js/p5/assets/bulgaria.mp3'.
Answers
P.S.: Please edit & choose "p5.js Library Questions" category for this type of question! :-\"
Thanks for the input!
The path in my code is relative, the same as in the example: ('assets/bulgaria.mp3'). Whether I load the sound in the preload function or the setup function, I get the same error.
W/o some mini-example demonstrating your issue I dunno what else to do, sorry! :(
I copied and pasted the code from the load and play sound example on p5.js reference, changed the name of the sound file to one I have in my assets folder and got the error I posted in the first message. I tried loading the file in a preload function and got the same error.
Maybe this is related: I'm trying to do a basic loadImage() and it's choking on the file, too.
Only family browser I'm able to play those sounds is Firefox. :-S
My loadSound function doesn't work in IE either, but loadImage does.
You are not allowed to access file from the client's machine in javascript... Java allows it but not Js... One way of doing it is put both(song file and Js) of them on a server...
Since it is a question about P5.js, I move this topic in the appropriate category.
@srinag of course is correct. In my recent post on alternatives to Sublime Text I mentioned that Brackets comes with a live preview option built in; which essentially runs a server for you locally and previews your sketch at the press of a button. In this case you shouldn't get hit by restrictions to loading local files; and you'll probably appreciate seeing things update automatically every time you save source files :)