Audio - Playing sound files without needing to Import

1

Stats

3,233 visits, 5,161 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 24 Apr, 2013. Last updated 19 Feb, 2019

INTRODUCTION

The manual entry for the Audio plugin covers from the point of importing sound files into the project... but there is no clear indication of whether you can actually do without this.

Well, there actually is a way to play sound files without the need to import any sound files at all.

A caveat that I would expect Scirra would want me to say is this: the Import function is very important as it encodes the required audio formats that will be supported by most browsers. But, if you know what you are doing, you can live without the import feature. Just use a conversion utility like Audacity (or something similar) to convert between the required sound file formats you need.

WHY?

Some of you may ask, "But what's the point of doing all this?"

Think ... here's one simple reason: do you want to upload a 100MB project every time to your server, all because you have a large number of audio files imported into your project?

Yes, sure, you could selectively zip folders ... but think again.

Here's another more plausible reason: let's say your game or application is dynamically expandable just by adding new levels and sound files ... now I'm sure you won't want to keep on changing your code right? So, code it in such a way that your project could grow infinitely without the need to export (or if you like - compile) again and again.

TUTORIAL

Let's assume you have a sound file whose name is beep. (File extension is not that critical here, just be aware of what sound formats your target browser can play.)

a. Open up a project. Let's call it MyProject.

b. Create an On start of Layout condition.

c. Add the following action to it: Play (by name).

d. For the parameters, type in "beep" for Audio file name. Note: the quotes are required while file extension is not required.

e. Export the project as an HTML 5 website.

f. Zip the project and upload it to your server.

g. On your server, unzip the project in a folder called MyProject.

h. Now this is important: In that folder, create a subfolder called media.

i. Upload the sound file beep into the new subfolder media.

j. Start up MyProject with your browser and enjoy the sound clip playing without the need to import into your project.

Remember:

-- you must have both ogg and m4a formats in the media folder to ensure compatibility with the major browsers out there, and;

-- you can use the Preload (by name) action to preload a sound file that was not imported into your project.

DEMO

A good example of this tutorial in action is shown as a demo over at my website - GamesWarp Studio. Check out the EBook Engine when you are there.

This engine is easily expandable on the fly just by uploading pictures and sound files into specific folders. This will obviously not work if you are using the import feature... you would have to fire up Construct 2, import in the new files, and then export your project all over again.

  • 0 Comments

Want to leave a comment? Login or Register an account!