AnimationDrawable variable speed

All your problems with Audio, Video and Images.

AnimationDrawable variable speed

Postby mistr » Mon Jul 18, 2011 6:24 pm

I'm trying to change the speed of an animation dynamically using a slider.

I tried the XML Animation file route, but I need to programmatically change the duration of each frame.
I decided to create an animation on the fly, and specify the duration of each frame myself. However, as the slider stops (user lifts their finger off the slider), my attempt to destroy and recreate an animation doesn't take.. the same original duration stays in effect.

Here is a sample snippet I have been trying to use:

Code: Select all
public class AnimationTest
extends Activity {
   
    AnimationDrawable animation;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        animation = new AnimationDrawable();
        animation.addFrame(getResources().getDrawable(R.drawable.ball1), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.ball2), 1000);
        animation.addFrame(getResources().getDrawable(R.drawable.ball3), 1000);
        animation.setOneShot(false);
       
        ImageView imageAnim =  (ImageView) findViewById(R.id.img);
        imageAnim.setBackgroundDrawable(animation);
       
        // run the start() method later on the UI thread
        imageAnim.post(new Starter());
       
    }
   
    class Starter implements Runnable {

        public void run() {
            animation.start();       
        }
       

    }
}


I have used the sample code above... and used the animation variable (type AnimationDrawable) to hook into the SeekBar, and yet I cannot get this to work. How can I properly release/destroy the animation and rebuild it with a new duration, like shown above (run the first time)? (and without "leaking" memory..)

Thanks
mistr
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Jul 12, 2011 8:28 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google Feedfetcher and 14 guests