Android App – Star Wars Sounds


I thought it would be fun to have a Star Wars soundboard on Android. I searched for existing ones on Google Play and found a few, but they were low quality in UI design and sound quality. StarWars.com has a flash soundboard with hundreds of high quality sound clips from the movies. I used these sounds for my app.

Playing sounds in Android:
At first I tried to use the SoundPool, but this preloads the sounds into memory and I had 350 sounds so the app would crash and also take forever to load. The better option was Android’s Media Player that plays the sounds on demand. I placed the mp3 files in the raw folder of my app and accessed them. Here’s some code snippets.

private void playSound(int resId) {
        try {
            if(mp == null) {
                mp = new MediaPlayer();
            }
            AssetFileDescriptor afd = this.getResources().openRawResourceFd(resId);
            mp.reset();
            mp.setVolume(1.0f, 1.0f);
            mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
            afd.close();
            mp.prepare();
            mp.start();
        } catch (Exception e) {
            Log.e("sw", "exception", e);
        }
    }

A friend noticed that his phone wouldn’t let his volume buttons control media player sounds unless there was a sound currently playing. To solve that I created a blank mp3 and had it looping the entire time during the app so volume control was easy to manage on devices. I loop this sound using setLooping(true);

    private void playBlank() {
        try {
            AssetFileDescriptor afd = this.getResources().openRawResourceFd(R.raw.blank);
            blankMp.reset();
            blankMp.setVolume(1.0f, 1.0f);
            blankMp.setLooping(true);
            blankMp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
            afd.close();
            blankMp.prepare();
            blankMp.start();
        } catch(Exception ex) {
            Log.e("sw", "exception", ex);
        }
    }

Here’s the app:
Star Wars Sounds App

This app is available here:
Google Play
Amazon Marketplace

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s