-
- /**
- * This class manages the loading/releasing/playing of the sounds needed for
- * countdown timer.
- */
- private class CountdownSoundPlayer {
- private SoundPool mSoundPool;
- private int mBeepOnce;
- private int mBeepTwice;
-
- void loadSounds() {
- // Load the beeps.
- if (mSoundPool == null) {
- mSoundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
- mBeepOnce = mSoundPool.load(mAppController.getAndroidContext(), R.raw.beep_once, 1);
- mBeepTwice = mSoundPool.load(mAppController.getAndroidContext(), R.raw.beep_twice, 1);
- }
- }
-
- void onRemainingSecondsChanged(int newVal) {
- if (mSoundPool == null) {
- Log.e(TAG, "Cannot play sound - they have not been loaded.");
- return;
- }
- if (newVal == 1) {
- mSoundPool.play(mBeepTwice, 1.0f, 1.0f, 0, 0, 1.0f);
- } else if (newVal == 2 || newVal == 3) {
- mSoundPool.play(mBeepOnce, 1.0f, 1.0f, 0, 0, 1.0f);
- }
- }
-
- void release() {
- if (mSoundPool != null) {
- mSoundPool.release();
- mSoundPool = null;
- }
- }
- }