0

Been in the process of finishing my baseball scoreboard and wanted to implement sound files to correspond with each buttons' press (cheers, awes, boos, whatever), but have been unable to successfully access sound files stored on computer or stored in the project itself. The code literally looks like this:

var cheer = new Audio(whole file path);
cheer.play();

...and nothing's working. Any ideas?

  • That is because JavaScript in the browser is not authorized to access content on the host computer. That's what is meant by being "sandboxed". – Randy Casburn Nov 24 '18 at 02:44
  • Possible duplicate of [Local file access with javascript](https://stackoverflow.com/questions/371875/local-file-access-with-javascript) – Randy Casburn Nov 24 '18 at 02:45
  • Appreciate the input, Randy. I wasn't aware that javascript was sandboxed. Luckily, I was able to get audio files to work from elsewhere by copying link locations close enough to the source. –  Nov 24 '18 at 21:15
  • You can read files from the host computer "if and only if" a user action starts the process. In other words, the user must "select a file" to be read by JS. That didn't sound like your use case, so I didn't mention it. – Randy Casburn Nov 24 '18 at 21:35
  • No, it wasn't. My thing is similar to what I would do while programming with Android Studio and having a res folder with images and such for the project. The issue I'm having is that the IDE isn't recognizing/allowing access to the resources contained within the project, and considering I can't always guarantee finding them elsewhere, it would be nice to know why this is happening and how to fix it. –  Nov 25 '18 at 22:13
  • Unless these things aren't uploaded when the project is compiled, in which case your answer seems to apply. –  Dec 05 '18 at 00:30

0 Answers0