Audio URL

Discussion and feedback on Construct 2

Post » Tue Aug 02, 2016 6:58 pm

Everybody says this is not supported because of the 2 file types. That is a no brainier.

But Since we are compiling 2 versions of code for different platforms we know how to set audio for that which we are working on.

Now to the question at hand. How to call an audio file from a web server.
B
29
S
13
G
10
Posts: 355
Reputation: 8,317

Post » Tue Aug 02, 2016 7:40 pm

Carbincopy wrote:Everybody says this is not supported because of the 2 file types. That is a no brainier.

But Since we are compiling 2 versions of code for different platforms we know how to set audio for that which we are working on.

Now to the question at hand. How to call an audio file from a web server.



you mean play an audio file? as mp3 etc? ... if so then u can use the video plugin i think its called you can play any file in it.. including mp3s since has the .h264 codec in it... however the file has to be on a public folder where anyone can read it.. outside that its pretty easy was a example in tutorials somewhere called ... playlist mp3 something...
B
75
S
22
G
68
Posts: 1,333
Reputation: 43,263

Post » Sun Aug 07, 2016 4:15 am

gamecorpstudio wrote:
Carbincopy wrote:Everybody says this is not supported because of the 2 file types. That is a no brainier.

But Since we are compiling 2 versions of code for different platforms we know how to set audio for that which we are working on.

Now to the question at hand. How to call an audio file from a web server.



you mean play an audio file? as mp3 etc? ... if so then u can use the video plugin i think its called you can play any file in it.. including mp3s since has the .h264 codec in it... however the file has to be on a public folder where anyone can read it.. outside that its pretty easy was a example in tutorials somewhere called ... playlist mp3 something...


Thank you will look that up. ;)
B
29
S
13
G
10
Posts: 355
Reputation: 8,317

Post » Sat Jan 28, 2017 8:21 am

Carbincopy wrote:Now to the question at hand. How to call an audio file from a web server.


@gamescorpstudio, the WebAudio API goodies aren't available to video unfortunately.

@mchulet, @Animate, @Carbincopy, I recently needed to do this and came up with a workaround (albeit hackish). So if you want to try, here goes.

This involves modding the Scirra audio plugin with a small change to the runtime.js and edittime.js

In my case, i just needed to reference .mp3's managed by a CMS exposed as a static site directory from a remote domain (ie. a web server). To keep things simple let's assume only using the Chrome browser and that mobile devices are out of the picture (I didn't need it in my case).

Let's say that our MP3 files are at http://www.yourdomain.com:8080/tracks/

1. Backup Scirra's audio plugin in case it gets messed up.

2. Edit the runtime.js and add a line after 3401 like so.
Image

3. Edit the edittime.js and change line 71 to the following.
Image

BUT... and here's the complicated bit.

4. You'll need to be the administrator of said server and be able to configure the appropriate Cross-Origin Resource Sharing (CORS) to ensure that your C2 application is allowed to GET those mp3's from wherever origin (domain) you're getting it from. Also note that when configuring CORS, you need to include the origin's port number as well (if any).

That's basically it.

During authoring time, just enter the URL (where the Folder property used to be). After a successful test, you can then think about reading an external JSON, iterating over an MP3 playlist and feeding the filenames to the (modified) audio plugin as a next step (see demo below).

Here's the modified plugin dialog for Play (by name) action. Notice the empty Sounds/Music folder:
Image


Finally, doing it this way would allow the continued use of the WebAudio API, filters and stuff. You get the idea.


EDIT:
How about an app that's hosted in Scirra Arcade which gets its audio from another site? Perfect example.
https://www.scirra.com/arcade/other-games/q3d-c2-webaudio-api-demo-again-15356

Image


EDIT 2:
If you have previous C2 projects using "PlayByName", beware that the above "hack" will break your previous project. However, the proper (less hackish) way that doesn't break previous C2 projects would be to extend the existing audio plugin with a new action, say "PlayFromURL", instead of modifying "PlayByName". But this requires a bit of plugin development know-how from your side to get done correctly (but is relatively easy).
I don't need a better iPhone, I need to be better.
B
25
S
10
G
20
Posts: 68
Reputation: 11,888

Previous

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 12 guests