00:00
00:00
Newgrounds Background Image Theme

Amandaerkul78 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

XMLHttpRequest to audio.ngfiles.com

1,769 Views | 4 Replies
New Topic Respond to this Topic

I want to create a sort of radio functionality in the game I'm working on, which will be hosted on NG. Is this permitted? How might I go about doing that?

In NetBeans, when I debug on localhost, it appears that NG doesn't allow these sorts of requests. I guess this is to reduce bandwidth usage.

Response to XMLHttpRequest to audio.ngfiles.com 2015-10-26 11:46:08


At 10/23/15 06:14 PM, MaxPoly wrote: I want to create a sort of radio functionality in the game I'm working on, which will be hosted on NG. Is this permitted? How might I go about doing that?

In NetBeans, when I debug on localhost, it appears that NG doesn't allow these sorts of requests. I guess this is to reduce bandwidth usage.

My guess is that the game content and the audio content you're trying to access are hosted at different domains, at which point your browser's same-origin policy will prevent the request from being fulfilled. Essentially, this is a safety feature in browsers that prevents rogue scripts (scripts not hosted on the same domain you're accessing the website from) from talking to a server they have no business talking to. It's intended to prevent stealing/modifying.

There is a way to get around it, but it requires changes on the server you want to access (audio.ngfiles.com) to indicate that the domain your script lives on is allowed to make XHR requests to it.

I don't think NG will want to make those changes given the security implications, though.

Further reading:

Cross-origin resource sharing (Wikipedia)

Using CORS (HTML5Rocks)

Response to XMLHttpRequest to audio.ngfiles.com 2015-10-31 16:47:14


Just wondering, then - since the audio is streamed in from audio.ngfiles.com when I view it in the audio portal, that means there's a way to get audio to play in my game as long as it's hosted here, right? I'm looking at the audio portal page source and it's not really giving me any hints.

Response to XMLHttpRequest to audio.ngfiles.com 2015-11-02 07:26:03


At 10/31/15 04:47 PM, MaxPoly wrote: Just wondering, then - since the audio is streamed in from audio.ngfiles.com when I view it in the audio portal, that means there's a way to get audio to play in my game as long as it's hosted here, right? I'm looking at the audio portal page source and it's not really giving me any hints.

Requesting plain files for playback does not necessarily use XHR, and so doesn't have these restrictions. Much like how you can embed images from any site on any other site. That said, even if it does use XHR for some reason (I don't think it does), newgrounds.com and audio.ngfiles.com are both (of course) controlled by NG, so they can add exceptions to allow the CORS request.

Games are likely hosted on yet another subdomain of nfiles.com, one which wouldn't have CORS access to audio.ngfiles.com

Response to XMLHttpRequest to audio.ngfiles.com 2015-11-02 17:02:03


At 11/2/15 07:26 AM, Mich wrote: Requesting plain files for playback does not necessarily use XHR, and so doesn't have these restrictions. Much like how you can embed images from any site on any other site. That said, even if it does use XHR for some reason (I don't think it does), newgrounds.com and audio.ngfiles.com are both (of course) controlled by NG, so they can add exceptions to allow the CORS request.

Games are likely hosted on yet another subdomain of nfiles.com, one which wouldn't have CORS access to audio.ngfiles.com

I'm assuming that NG radio flash submission is given special privileges by the AS3 API then, right? Since NG doesn't have an official Javascript API, I'd have to use flash?