我目前有一個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