public synchronized void playSound(String name, boolean loop) { if (paused) { return; } if (sounds.containsKey(name)) { ((AssetsSound) sounds.get(name)).play(); } else { if (clipCount > MAX_CLIPS) { int idx = sounds.size() - 1; String k = (String) sounds.keySet().toArray()[idx]; AssetsSound clip = (AssetsSound) sounds.remove(k); clip.release(); clip = null; clipCount--; } asound = new AssetsSound(context); asound.setDataSource(name); if (loop) { asound.loop(); } else { asound.play(); } sounds.put(name, asound); clipCount++; } }
public synchronized void stopSoundAll() { if (sounds != null) { for (Iterator<?> it = sounds.iterator(); it.hasNext(); ) { Entry<?, ?> sound = (Entry<?, ?>) it.next(); if (sound != null) { AssetsSound as = (AssetsSound) sound.getValue(); if (as != null) { as.stop(); } } } } }