开发者

Animation Drawable with Sound in android?

I use the animation drawable functionality in my class.

I need t开发者_运维知识库o generate the sound while each frame of animation is loaded.Whether it is possible or not. I use the following code for animation:

<?xml version="1.0" encoding="utf-8"?>
<animation-list   android:id="@+id/handimation" android:oneshot="false" 
    xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:drawable="@drawable/count3" android:duration="650" />
    <item android:drawable="@drawable/count2" android:duration="650" />
     <item android:drawable="@drawable/count1" android:duration="650" />
     <item android:drawable="@drawable/go" android:duration="650" />
 </animation-list> 

My Java:

AnimationDrawable frameAnimation;
         ImageView animatedimage ;
animatedimage = (ImageView)findViewById(R.id.rcount);
              final MyAnimationRoutineStart animationStart = 
                                          new MyAnimationRoutineStart();
              final MyAnimationRoutineStop animationStop = 
                                           new MyAnimationRoutineStop();
animatedimage.setBackgroundResource(R.drawable.spin);
frameAnimation = (AnimationDrawable) animatedimage.getBackground();
Timer animateTimerStart = new Timer(false);
animateTimerStart.schedule(animationStart, 100);
Timer animateTimerStop = new Timer(false);
animateTimerStop.schedule(animationStop, 2500);

class MyAnimationRoutineStart extends TimerTask
        {
            MyAnimationRoutineStart()
            {

            }
            public void run()
            {
            // Start the animation (looped playback by default).
                frameAnimation.start();


            }
        }

        class MyAnimationRoutineStop extends TimerTask
        {
            MyAnimationRoutineStop()
            {       
            }

            public void run()
            {
            frameAnimation.stop();
            // stop the animation (looped playback by default).

            videoName=camcorderView.startRecording();
            counter = 0;
            counterFlag = true;
            counterThread.start();


            }
          }

I don't know where to generate the sound.

Any one suggest some idea.

Thanks.


I achieved that using a handler. Inside the handler, I start and play the sound and delay the handler message for the duration of each animation frame. It is working fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜