Adding music while keeping app size small

For the longest time I was bothered by how much space my audio files were taking in my app. Space is at a premium on mobile devices and I wanted to keep my app size as lean as possible. I did some searching and documented what I found in a blog post.

http://freezeraystudios.com/blog/adding-music-while-keeping-app-size-small/

For those who want the meat and potatoes, here it is:

  1. Don’t use .wav format if you have a lot of songs. They are pretty big. Convert your files to .ogg for Android and .aac for iOS. You’ll cut the file size in half (or more) and retain good quality.
     

  2. In the code for your audio manager, detect which platform you are on so that you can dynamically choose the right file format for your audio. Something like this:

    local AudioManager = {} --Get the OS platform so we know the proper music format local platform = system.getInfo(“platformName”) --Assumes that you’re either on android or iOS --You should update this depending on what platforms you --want to target. local musicFormat = platform == “Android” and “.ogg” or “.aac” function AudioManager:playMusic(trackName) local track = audio.loadStream( “path/to/music/”…trackName…musicFormat ) audio.play( track, { channel = 1, fadeIn = 3000, loops = -1 } ) end return AudioManager

Make use of Corona’s exclusion feature in your build.settings. This will make sure that only the appropriate music files are included in the build for each platform. Add something like this to your build.settings:

excludeFiles = { -- Exclude all Android music files for the iOS version iphone = { "\*.ogg" }, -- Exclude all iOS music files for the Android version android = { "\*.aac" } },

Enjoy good quality music and a smaller file size!