Game Development Reference
In-Depth Information
return am;
}
private AudioManager(Context ctx) {
mContext = ctx;
preloadSounds(ctx);
}
/**
* Start a sound by name & volume
* @param idx Sound idx (see SoundNames for mappings)
*/
public synchronized void startSound(int sidx) {
if (sidx == 0)
return;
if (sidx < 0 || sidx > SoundNames.Sounds.length) {
return;
}
// The sound key
int id = SoundNames.Sounds[sidx];
String key;
if (id == 0)
return;
try {
key = mContext.getResources().getResourceName(id);
} catch (NotFoundException e) {
return;
}
if (mSounds.containsKey(key)) {
// Play from cache
mSounds.get(key).play();
} else {
// load clip from disk
// If the sound table is full last entry
if (mClipCount > MAX_CLIPS) {
// Remove a last key
int idx = mSounds.size() - 1;
String k = (String) mSounds.keySet().toArray()[idx];
AudioClip clip = mSounds.remove(k);
clip.release();
clip = null;
mClipCount--;
}
AudioClip clip = new AudioClip(mContext, id);
Search WWH ::




Custom Search