我目前有一个SoundPool加载并在屏幕抖动时播放单个声音,如何在每次屏幕抖动时播放不同的声音?从原始文件夹播放随机声音
编辑---
private SensorManager mSensorManager;
private ShakeEventListener mSensorListener;
SoundPool sp;
int soundOne;
int soundTwo;
int soundThree;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
//Shake sound
sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
soundOne = sp.load(this, R.raw.one, 1);
soundTwo = sp.load(this, R.raw.two, 1);
soundThree = sp.load(this, R.raw.three, 1);
//Shake
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensorListener = new ShakeEventListener();
mSensorListener.setOnShakeListener(new ShakeEventListener.OnShakeListener() {
public void onShake() {
if (acceptCheck == 1)
{
sp.play(soundOne, 1, 1, 0, 0, 1);
}
}
});
}
你将不得不加载所有你想从成列表中进行选择的声音,然后选择一个随机指数。如果您需要更多帮助,您将需要发布更多代码。 – cbrulak
我已经更新了我所拥有的内容,因为您可以在onShake中看到它只能播放soundOne,我将如何适应播放其中一种声音的随机播放? – SpunkTrumpet