I'm starting to play with doing some simple animations.
I have one where I want a sound and animation to play every X seconds
after a button is pressed.
So I set it up like this:

        private ScheduledThreadPoolExecutor threadRunner = new
ScheduledThreadPoolExecutor(
                        4);
        private SoundPlayer mSoundPlayer = new SoundPlayer();
        private ScheduledFuture<SoundPlayer> playerFuture = null;


        private OnClickListener mClickButton = new OnClickListener() {
                public void onClick(View v) {
                        Button button = (Button) findViewById(R.id.Button01);
                        if (playerFuture != null) {
                                button.setText(R.string.Button01);
                                playerFuture.cancel(false);
                                playerFuture = null;
                        } else {
                                button.setText(R.string.BtnStop);
                                playerFuture = (ScheduledFuture<SoundPlayer>)
threadRunner.scheduleAtFixedRate(mSoundPlayer,
                                                0, 3000, TimeUnit.MILLISECONDS);
                        }
                        return;
                }
        };

        private class SoundPlayer implements Runnable {
                private MediaPlayer mPlayer;
                private TextView testShape;
                private Animation testAnimation;

                public void run() {
                        if (mPlayer == null) {
                                mPlayer = MediaPlayer.create(getBaseContext(), 
R.raw.ding);
                                testShape = (TextView) 
findViewById(R.id.TextView02);
                                testAnimation = 
AnimationUtils.loadAnimation(getBaseContext(),
R.anim.testanim);
                        }
                        mPlayer.start();
                        testShape.startAnimation(testAnimation);
                        return;
                }
        }

The problem is that the call to "startAnimation" seems to stop the
timer.
The sequence of events is:

Press Button (starts timer)
Sound plays once
Press Button (to stop the timer)
Animation plays once
Press Button (starts timer)
Sound & Animation play once
Press Button (stops timer)
nothing happens
Press Button (starts timer)
Sound & Animation play once
...

If I remove the call to testShape.startAnimation(), the timer runs,
and the sound plays every 3 seconds until the button is pressed again.

I must be doing something wrong with the animation, but I haven't been
able to figure out what.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to