package com.icystar.findnumber;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.SparseArray;
public class SoundPlayer {
private static Object handle = new Object();
private static boolean enabled = true;
private static SoundPool pool;
private static SparseArray<Integer> map;
public static void initSounds(Context context) {
synchronized (handle) {
if (pool == null || map == null) {
pool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
map = new SparseArray<Integer>(5);
map.put( R.raw.sound_player1_clicked, pool.load(context, R.raw.sound_player1_clicked, 1) );
map.put( R.raw.sound_player2_clicked, pool.load(context, R.raw.sound_player2_clicked, 1) );
map.put( R.raw.sound_lock, pool.load(context, R.raw.sound_lock, 1) );
map.put( R.raw.sound_win, pool.load(context, R.raw.sound_win, 1) );
map.put( R.raw.sound_test, pool.load(context, R.raw.sound_test, 1) );
}
}
}
public static void playSound(int id) {
synchronized (handle) {
if (enabled && pool != null && map != null && map.indexOfKey(id) >= 0)
pool.play(map.get(id), 1, 1, 1, 0, 1f);
}
}
public static boolean getEnabled()
{ synchronized (handle) { return enabled; } }
public static void setEnabled(boolean value)
{ synchronized (handle) { enabled = value; } }
}