How to play sound in while performing certain Anim

2019-05-27 03:58发布

问题:

I am making an App which does certain processing for 5 seconds and then giving a result. During that time I want to apply some Animation and play some sound to avoid user to sit idle watching whats happening.

I have applied the Animation and need some help in how to play sound for that particular time. I have one sound file for 5 seconds.

Any ideas are very welcomed.

回答1:

Try reading the documentation of:

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

This handles playing sounds on the OS.



回答2:

Animation myAnimation = AnimationUtils.loadAnimation(this, R.anim.myanimation);
animationFalling.setAnimationListener(new AnimationListener() {

    @Override
    public void onAnimationStart(Animation animation) {
         //here you can play your sound
    }

    @Override
    public void onAnimationRepeat(Animation animation) {
    }

    @Override
    public void onAnimationEnd(Animation animation) {
         // here you can stop playing your sound
    }
};

About how to play your sound, there is MediaPlayer or SoundPool in order to play them.