jmt
jmt

Reputation: 223

android application running very slow

I have developed a simple piano application on android OS. It works successfully but very slowly. Can anyone tell me how to make it work faster?

 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;
          }
        }

Upvotes: 0

Views: 749

Answers (1)

Philipp Jahoda
Philipp Jahoda

Reputation: 51411

I recommend using SoundPool instead of MediaPlayer for better performance. You can read about Soundpool and its usage here:

http://developer.android.com/reference/android/media/SoundPool.html

And some example code:

http://www.edumobile.org/android/android-programming-tutorials/sound-pool-example-in-android-development/

Upvotes: 1

Related Questions