public
class
SoundControl
extends
Activity{
public
static
final
int
BASE =
1
;
public
static
final
int
ACTION =
2
;
public
static
final
int
GEAR =
3
;
private
static
final
int
BASE_SOUND =
10
;
SoundPool base_sound =
null
;
SoundPool action_sound =
null
;
SoundPool gear_sound =
null
;
private
AudioManager audio;
int
baseId;
int
actionId;
int
gearId;
public
void
soundCreate(
int
id) {
Context context =
new
SoundRacerActivity();
switch
(id) {
case
BASE:
base_sound =
new
SoundPool(
1
, AudioManager.STREAM_MUSIC,
0
);
baseId = base_sound.load(context, R.raw.porsche_911_gt3_rs_basics2,
1
);
audio.setStreamVolume(AudioManager.STREAM_MUSIC, BASE_SOUND,
0
);
break
;
case
ACTION:
action_sound =
new
SoundPool(
1
, AudioManager.STREAM_MUSIC,
0
);
actionId = action_sound.load(context,
R.raw.porsche_911_gt3_rs_exhaust1,
1
);
break
;
case
GEAR:
gear_sound =
new
SoundPool(
1
, AudioManager.STREAM_MUSIC,
0
);
gearId = gear_sound.load(context,
R.raw.porsche_911_gt3_rs_shift_gears,
1
);
break
;
}
}
public
void
play(
int
id) {
switch
(id) {
case
BASE:
base_sound.play(baseId,
1
.0f,
1
.0f,
0
, -
1
,
1
.0f);
break
;
case
ACTION:
action_sound.play(actionId,
1
.0f,
1
.0f,
0
, -
1
,
1
.0f);
break
;
case
GEAR:
gear_sound.play(gearId,
1
.0f,
1
.0f,
0
, -
1
,
1
.0f);
break
;
}
}
public
void
pause(
int
id) {
switch
(id) {
case
BASE:
base_sound.pause(baseId);
break
;
case
ACTION:
action_sound.pause(actionId);
break
;
case
GEAR:
gear_sound.pause(gearId);
break
;
}
}
public
void
release(
int
id) {
switch
(id) {
case
BASE:
base_sound.stop(baseId);
base_sound.release();
base_sound =
null
;
break
;
case
ACTION:
action_sound.stop(actionId);
action_sound.release();
action_sound =
null
;
break
;
case
GEAR:
gear_sound.stop(gearId);
gear_sound.release();
gear_sound =
null
;
}
}
public
void
audioInitial() {
audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audio.setStreamVolume(AudioManager.STREAM_MUSIC, BASE_SOUND,
0
);
}
public
void
audioVolumeControl(
int
vol) {
audio.setStreamVolume(AudioManager.STREAM_MUSIC, vol,
0
);
}
public
void
stop() {
if
(action_sound !=
null
) {
action_sound.stop(actionId);
action_sound.release();
action_sound =
null
;
}
else
if
(base_sound !=
null
) {
base_sound.stop(baseId);
base_sound.release();
base_sound =
null
;
}
else
{
gear_sound.stop(gearId);
gear_sound.release();
gear_sound =
null
;
}
}