1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package com.camilstaps.rushhour;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
/**
* Wrapper for SoundPool for app-wide sounds
* Created by camilstaps on 29-4-15.
*/
public class TheSoundPool {
private static SoundPool soundPool;
public static int soundBackgroundId, soundCarDriveId, soundCantMoveId, soundVictoryId;
/**
* Initialise everything if not done yet
* @param context
* @return
*/
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;
}
}
|