Game Development Reference
In-Depth Information
clip.play();
mSounds.put(key, clip);
mClipCount++;
}
}
/**
* PreLoad the most used sounds into a hash map
*
* @param ctx App context
* @return
*/
// public void preloadSounds(Context ctx) removed for simplicity
/**
* Start background music
* @param ctx
* @param midx Music index, See SoundNames for mappings
*/
// public void startMusic(Context ctx, int midx) Removed for simplicity
}
Creating the Audio Clip
This is the final piece of the puzzle. AudioClip wraps the Android media player and provides methods for
(see Listing 6-13):
Creating a clip using a resource ID or URI
Playing or looping a sound
Stopping a sound
Setting the volume
AudioClip deals with the nasty idiosyncrasies of the media player such as illegal state exceptions
when the resources are not prepared, played, or stopped in the right sequence.
Listing 6-13. The Audio Clip Class for Wolf 3D.
package wolf.audio;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
public class AudioClip {
static final String TAG = "AudioClip";
Search WWH ::




Custom Search