Load resources from external web site

Hello. I’m using cocos2d js for developing game and distribute it on mobile platforms (iOS/Android)
Is it possible somehow to get resources from external URLs being in runtime?
I mean this:
cc.audioEngine.playEffect("http://mywebsite.com/res/audio/sound.wav", false);
I know, this may look pointless and weird, but I really need it)
Would be appreciated for any workaround as well.

1 Like

hiho

you’ll need to do something about cross origin resource sharing.

an easy solution is using http://cors.io/

http://cors.io/?http://www.yoururlhere.org

adding this will allow you to load data from external sites.

cheers

is it critical for native apps too? (i mean cors)
the thing is that I tried to run the code above, I also tried to preload sounds via AudioEngine feature, but I can’t see the app is accessing web resources. I own the server, i have an access to web logs.

At the moment my goal is to understand whether it’s technically possible at all?

OK, I’ve finally invented a workaround. Maybe it will be useful for someone, I’m gonna keep it here.
http://heximal.ru/blog/en/coding/cocos2d-js-zagruzit-vneshnie-audio-fajly-i-javascript-kod/

I also need the ability to load audio from URLs (like in Unity). Calling cc.loader.loadRes with a URL isn’t enough – it does not work. Of course, I’d strongly prefer to not use an unsupported workaround for such critical functionality for our app.

Any idea if this is on the roadmap? @slackmoehrle ? Thanks! :slight_smile:

Bump, we actually will need this within the next few weeks. Is this feature (load audio from web URL instead of file path) on your roadmap?

Bump.

I was shocked to learn this can’t be done. We need the ability to load other external asset types from external sources (scenes, prefabs, animations) not just audio. @slackmoehrle, could you please comment if this is on the roadmap? Feels like really basic functionality to me.

1 Like

Sure. Let me find out.

1 Like