我在安卓操作系统上开发了一个简单的钢琴应用程序。它工作成功,但非常缓慢。谁能告诉我如何让它更快地工作?
public class MainActivity extends Activity implements OnClickListener{
@Override
public void onClick(View v) {
if(v.equals(b1)){
sound = R.raw.piano_f;
}else if(v.equals(b2)){
sound = R.raw.piano_e;
}
new MyTask(MainActivity.this,sound).execute();
}
}
class MyTask extends AsyncTask<Void, Void, Void>{
int sound;
Context context;
public MediaPlayer media;
MyTask(Context context , int sound){
this.sound = sound;
this.context = context;}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
media = MediaPlayer.create(context,sound );
media.start();
return null;
}
}