Adding music while keeping app size small

Ok, you’ve made progress on your game and things are coming together. Your gameplay is polished and actually pretty fun. Your artwork is looking great. It’s time to add that cherry on top that completes your game experience…music!

There’s only one problem, you’d like to have a bunch of songs in your soundtrack but high quality music files take up a lot of space. A 1 minute track could easily take up 5MB depending on what audio format you use. In the mobile world, space is precious, especially on Android where your apk size for the Play Store is limited to 50MB (unless you want to deal with pesky expansion files).

I faced this problem recently when adding music to my game. At first, I wanted to keep things simple so I chose the .wav format for cross-platform audio compatibility. But I soon learned that all my audio files combined were adding a hefty 20-25MB to my game! I tried reducing the sample rate, which made the files a little smaller but the audio quality suffered greatly.

I was not content so I did some googling and found a combination of tricks to trim some of the fat in my app.

Going back to that page on Corona audio formats, I noticed that Android supports .ogg and iOS supports .aac. These file formats are compressed but offer great audio quality, and best of all, they don’t come with weird royalty restrictions like .mp3 does. I found this neat website that will convert your formats for you for free, and it even gives the option to change certain settings and trim the length of the song. You can check it out here (Note: unfortunately, I recommend using an ad blocker on this site as they have some intrusive ads). The settings that I recommend to keep the best sound are

Bitrate: 128 kbps
Sampling Rate: 44100 Hz
Audio Channels: Mono

Now, you may be saying to yourself, “I have double the amount of files, how does this help me reduce the app size?”. There are still a couple more pieces we need to make this work.

First, let’s take a look at a simplified audio manager that automatically selects the file format based on what platform we are on:

Lastly, let’s look at where the magic happens. Corona has this awesome feature that lets you exclude files from your build, and it even supports excluding certain files based on the platform you are targeting! Open up your build.settings file and drop this into the settings table:

And there you have it! Compressed audio, dynamic format selection, and reduced app size. Your game is now one step closer to being production ready. Happy coding!

Corona SDK: Customizing the Facebook Share Dialog using dynamic meta tags

This may be obvious for some, but it took me some digging and I figured I would share what I learned in a nice, easy to digest format.

Facebook documentation recommends the share dialog over the feed dialog for mobile developers. It’s supposed to be the easiest way to share stuff from your app. It doesn’t seem to be documented, but Corona supports the share dialog.

Feed allows you to pass in a name, caption, description, and a link to customize your dialog. Share on the other hand, only takes an href parameter — this is the url for your page. When you activate the share dialog, Facebook scrapes your page looking for specific meta tags to fill in the content.

Normally these meta tags are static, but if you want to take your sharing to the next level, you can dynamically generate them using a bit of server side code.

Note: The following assumes you have facebook configured with your app and that you have access to a server running php.

First, let’s look at the Lua code for Corona:

Notice that we are encoding a score and level Id into the url. Pretty simple so far!

Next, let’s look at the contents of share.php:

And that’s all it takes! Facebook has a nifty tool to verify that your meta tags are being read properly. You can check it out here. Simply enter your href with some sample values to see the results.


You may be wondering why you should go through all the trouble to use Share instead of Feed. The main advantage is that you can update your meta tag content on your server, and have it propagate to all versions of your app immediately instead of building and pushing out an update just to change one or two dialog properties.

Hopefully this helps a few of you!