当按下android屏幕上的按钮并且所有音频质量听起来都很棒时,我在eclipse中获取一些音频文件没有问题:java可以正常播放。然而,我正在尝试制作的程序是一个节拍制作工作室,你只能这么快地按下按钮。之前按下相同的按钮(大约 0.5 秒)后,您可以按下按钮来触发音频样本的时间会稍有延迟。显然,当能够在所需时间按下按钮非常重要时,这会给音乐应用程序带来问题。关于如何让我的应用程序允许更快地按下按钮的任何建议?
package studio.music;
import android.app.Activity;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class StudioActivity extends Activity implements OnClickListener{
MediaPlayer mp1,mp2;
Button button_one,button_two;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) { //The activity is being Created Create any threads/streams here
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mp1 = MediaPlayer.create(this, R.raw.bassfifteen);
mp2 = MediaPlayer.create(this, R.raw.snarenine);
button_one = (Button) findViewById(R.id.buttonOne);
button_one.setOnClickListener(this);
button_two = (Button) findViewById(R.id.buttonTwo);
button_two.setOnClickListener(this);
}
@Override
protected void onStart(){ //The activity is about to become visible
super.onStart();
//TODO set state for program start
}
@Override
protected void onResume(){ //The activity has become visible(it is now "resumed")
super.onResume();
//TODO set state for program resume
}
@Override
protected void onPause(){ // Another activity is taking focus (this activity will be "paused")
super.onPause();
//TODO set state for program hang
}
@Override
protected void onStop(){ // This activity is no longer visibled (it is "stopped")
super.onStop();
//TODO set state for program drop back
}
@Override
protected void onDestroy(){ // The Activity is about too be destoryed (exiting) Destroy all threads and streams here
super.onDestroy();
//TODO set state for program exit
}
@Override
public void onClick(View v) {
//Where the audio is fired
if(v == button_one){ mp1.start();}
if(v == button_two){ mp2.start();}
}
}