diff options
Diffstat (limited to 'app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java')
-rw-r--r-- | app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java b/app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java new file mode 100644 index 0000000..c727979 --- /dev/null +++ b/app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java @@ -0,0 +1,34 @@ +package com.camilstaps.rushhour; + +import android.content.Context; +import android.media.AudioManager; +import android.media.SoundPool; + +/** + * Created by camilstaps on 29-4-15. + */ +public class TheSoundPool { + + private static SoundPool soundPool; + public static int soundBackgroundId, soundCarDriveId, soundCantMoveId, soundVictoryId; + + public static SoundPool getSoundPool(Context context) { + if (soundPool == null) { + soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0); + soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { + @Override + public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { + if (sampleId == soundBackgroundId) { + soundPool.play(soundBackgroundId, 1, 1, 2, -1, 1); + } + } + }); + soundBackgroundId = soundPool.load(context, R.raw.tune, 2); + soundCarDriveId = soundPool.load(context, R.raw.car_drive, 1); + soundCantMoveId = soundPool.load(context, R.raw.cantmove, 1); + soundVictoryId = soundPool.load(context, R.raw.victory, 1); + } + return soundPool; + } + +} |