I have a animation xml file:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/anim"
android:oneshot="true" >
<item
android:drawable="@drawable/pik1"
android:duration="150"/>
<item
android:drawable="@drawable/pik2"
android:duration="150"/>
</animation-list>
What i want to do is start and keep running the animation while mediaplayer is playing and stop the animation when mediaplaye is finished playing.
For Example: The mediaplayer is playing a sound which is 5 seconds long, i want to play the animation for 5 seconds an then stop is.
This is the jave code i have in my main activity:
piks.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (play != null) {
play.reset();
play.release();
}
play = MediaPlayer.create(pikselActivity.this,
R.raw.pisound);
play.start();
frame.start();
}
});
frame.start() starts the animation, but when the sound is finished, the animation keeps running. How do i make the animation stop when the sound is finished?
put an onCompletionListener() on your media player. Inside the callback for media complete add
like this: