0 Favourites

Audio URL

  • Hi,

       Is it possible to play an audio file by passing in URL to the audio file, I could not find this option in the Audio Plugin.

    -Thanks

  • The main reason this isn't supported is because you need to dual-encode all your audio to two formats for it to play on all platforms. So if you play example.com/audio.ogg, it won't work on Microsoft or Apple platforms, and if you play example.com/audio.m4a, it won't play on some Firefox or other open-source platforms. The best thing to do is import the audio file to your project so Construct 2 dual-encodes it and then play it from there.

  • In this project I don't have the option of embedding all sound files within the project. There are quite a few of them and not all of them would be required in any single run.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • According to the audio manual entry:

    udio is downloaded on demand

    To speed up the loading time and start the game sooner, audio is downloaded or streamed on-demand during the game. In other words, nothing is downloaded until a Play action starts playing an audio file. Then, if the audio file is in the Music folder it starts streaming from the server; if in the Sounds folder, it starts downloading and will play when finished downloading.

    Looks like you already have exactly what you need ?

    Make sure to preload all required sounds (like menu fx for example) on the start of your game, and possibly you could get over with "Play" at any needed time.

    This will be dependent on the bandwidth of your users though.

  • No Kyatric, that works only for sound files that are part of the project. It does not work for referring to sound files at runtime.

    -Thanks

  • For what it's worth... it works swell for me. And as Kyatric says, it works... but you don't really need a URL per se.

    Just upload all your sound files to the media folder. This folder must reside as a subfolder in your project. So even if you have not imported any sound or music into your project, you can always create it on your server. As to the sound files you put inside - it's best you convert them to both ogg and m4a format.

    As for coding, just use the "Play (by name)" action and key in the filename without extension.

    Voil?!

  • For what it's worth... it works swell for me. And as Kyatric says, it works... but you don't really need a URL per se.

    Just upload all your sound files to the media folder. This folder must reside as a subfolder in your project. So even if you have not imported any sound or music into your project, you can always create it on your server. As to the sound files you put inside - it's best you convert them to both ogg and m4a format.

    As for coding, just use the "Play (by name)" action and key in the filename without extension.

    Voil?!necromaster2013-04-24 09:46:43

    Is this actually tested and functional? I'll have to try it myself.

  • It worked for me back then. I should assume it still works with the current version. Try it out and share with us your findings.

  • This works for audio files that are stored in the media folder. What about sound files that are stored in another server? Similar to mchulet, i am working currently in a project with thousands of audio files.

    How would i request the URL of the audio files on another server, would it be through an AJAX get request?

  • 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.

  • 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...

  • > 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.

  • 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.

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

    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:

    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

    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).

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)