1
我正在爲學校創建一個採樣器應用程序。我編寫了一些代碼,當我按下按鈕時播放一個樣本,當我釋放它時停止播放。我的問題是它有太多的延遲。按下按鈕播放聲音後需要很長時間。按下按鈕後播放聲音的延遲太長
我的音頻文件是mp3的。
這裏是我的代碼:
smpl1.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View arg0, MotionEvent theMotion)
{
switch (theMotion.getAction())
{
case MotionEvent.ACTION_DOWN:
sample = MediaPlayer.create(MainActivity.this, R.raw.bassdrum);
smpl1.setText("ON");
smpl1.setTextColor(Color.GREEN);
sample.start();
break;
case MotionEvent.ACTION_UP:
smpl1.setText("OFF");
smpl1.setTextColor(Color.RED);
sample.stop();
break;
}
return true;
}
您可能還需要「準備」它 – njzk2