Sound Doesn't Work

Hi, I'm a big fan of Processing and I'm psyched about p5.js. The visual stuff is working great, but I'm having a problem with the most basic sound stuff in Chrome and IE. I copied the first example from the p5.js sound page and put a sound file in my assets folder. When I run the page locally, I get this error. Any ideas what I'm doing wrong?

Thanks in advance!

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'.

Tagged:

Answers

  • edited April 2015 Answer ✓
    • Those browsers don't like scripts or loading resources offline by default.
    • My advise is Firefox or some other derivative like Seamonkey, Waterfox, Palemoon, etc.
    • Or even better, Firefox Developer Edition: https://www.mozilla.org/en-US/firefox/developer/
    • All of them work offline. No need to run your page through a server! ;)
  • Finally, it worked under Firefox developer edition. Has anybody gotten it to work on Chrome? I'm running the pages offline.

    Anyway, thank you for the advice.

  • You could also use Python to run a local server. If you're on Mac OS X 10.8 or later, it should come with Python installed.

    To use it, open the Terminal and navigate to your project folder by typing cd your-folder-path. If you are not sure what is the path you can drag the folder from a finder window into your terminal window.

    After you're in your project folder, enter python -m SimpleHTTPServer 8000 to start a local server. You can access it in any browser by typing localhost:8000 in the url bar. This should solve the issue of loading files from your hard drive.

    Here's the Python simple server docs: https://docs.python.org/2/library/simplehttpserver.html

  • This is standard behaviour in Chrome/IE: you need to use a local server; but you don't have to go through the hassle of setting one up: just use p5 IDE or Brackets both of which have a local server built in and which runs at the push of a button...

  • edited November 2015

    For SlimJet (which is a Chromium/Chrome derivative browser) I use:
    "C:\Program Files\Slimjet\slimjet.exe" --allow-file-access-from-files in its shortcut.
    But as I've mentioned before, Firefox family browsers don't have any problem to run local file scripts. \m/

Sign In or Register to comment.