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