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