aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java
blob: c7279793547357473043fc02aaab5d0aaa98e8f7 (plain) (blame)
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
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;
    }

}