ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This is the second time in as many weeks that I've come with questions about somewhat esoteric issues.
I'm attempting use the Howler JS library. If I use a CDN, and try to play a local sound, I get this error:
Code:
Failed to load file:///H:/HTML/Test/assets/sounds/bubbles.mp3: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
If I try to save the Howler library locally, I get this error:
Code:
Uncaught SyntaxError: Unexpected token <
So, using the CDN, Howler will apparently work, but errors out on locally saved sounds. Use a locally saved library and the browser is apparently startled by the first < in the Howler file.
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
padding: 0;
background: darkviolet;
}
Javascript:
Code:
$("body").on("keypress", function(e) {
if (e.which === a) {
play(bubbles);
}
});
var bubbles = new Howl({
src:['assets/sounds/bubbles.mp3'],
volume: 0.7
});
Any ideas, folks?
Thanks,
Doug
Last edited by killingthemonkey; 03-06-2018 at 10:36 PM.
Well... I figured it out. I did the obvious thing. I compared the two Howler files. I was going to run diff on them, but apparently, my locally saved file wasn't Howler at all. It was instead an HTML file. Turns out, I downloaded the wrong file.
if i understand correctly, ALL javascript implementations disable cross-origin requests by default.
a local file apparently defines as a different origin from where the script was called from.
plenty of Q/A about this on e.g. stackoverflow.
If I use a CDN, and try to play a local sound, I get this error:
Code:
Failed to load file:///H:/HTML/Test/assets/sounds/bubbles.mp3: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
If you are using CDN then you must be using http protocol to get it, but you are using file protocol to load the sound file - the error explicitly says that is not supported. Have you tried using http locally to get the sound file? (Hint: Make it accessible via your localhost web server, assuming you have one running, so the sound file may be accessed something like this: http://localhost/path/to/bubbles.mp3).
The same would apply for a locally served howler.js - if you load it via http, you must load the sound file via http also - the local web server cannot see outside its own root filesystem..
I am unsure what would happen if you try to load both howler and the sound file via file protocol, but I suspect that would not work either, but I am not sure what constitutes an "origin" for files loaded into a browser locally.
If loading the sound file via http does not seem to work, please tell us exactly how you are loading the "page" into your browser, and the full path paths to howler.js and bubbles..mp3 and exactly what errors you see.
Last edited by astrogeek; 03-07-2018 at 11:24 PM.
Reason: typos, added comment, defang url
^ oh, i think i didn't read the error message properly:
"Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https."
the data scheme looks promising?
ondoho,
I believe it was definitely that I was trying to use the file protocol. I fired up VirtualBox and installed a LAMP stack. Running the page from a server, it worked.
If loading the sound file via http does not seem to work, please tell us exactly how you are loading the "page" into your browser, and the full path paths to howler.js and bubbles..mp3 and exactly what errors you see.
astrogeek,
This worked. I ended up setting up a LAMP stack to serve up the page. Issue resolved.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.