Blame |
Last modification |
View Log
| RSS feed
package com.gebauz.pingK;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
public class Sounds
{
private final int[] resourceIds
;
private final int[] soundPoolIds
;
private SoundPool soundPool
;
private AudioManager audioManager
;
private boolean soundsOn
;
public Sounds
(int[] soundResourceIds
) {
this.
resourceIds = soundResourceIds
;
soundPoolIds =
new int[soundResourceIds.
length];
soundsOn =
true;
}
public void init
(Context context
) {
soundPool =
new SoundPool
(200, AudioManager.
STREAM_MUSIC,
100);
audioManager =
(AudioManager
) context.
getSystemService(Context.
AUDIO_SERVICE);
for (int i =
0; i
< resourceIds.
length; i++
) {
soundPoolIds
[i
] = soundPool.
load(context, resourceIds
[i
],
100);
}
}
public void destroy
() {
audioManager =
null;
soundPool.
release();
soundPool =
null;
}
public void playSound
(int sound
) {
if (soundPool
!=
null && soundsOn
) {
for (int i =
0; i
< resourceIds.
length; i++
) {
if (sound == resourceIds
[i
]) {
int streamVolume = audioManager.
getStreamVolume(AudioManager.
STREAM_MUSIC);
soundPool.
play(soundPoolIds
[i
], streamVolume, streamVolume,
1,
0, 1f
);
break;
}
}
}
}
public boolean isSoundsOn
() {
return soundsOn
;
}
public void setSoundsOn
(boolean soundsOn
) {
this.
soundsOn = soundsOn
;
}
}