Aboudi Aboudi - 5 months ago 40
Android Question

How to use the VideoView .isPlaying() method?

My Aim is to play a repeating animation for the duration the video is played, as I am using a VideoView I thought that I might as well take advantage of the .isPlaying method to resolve implement this however the while loop does not execute at all

Floater0 = (ImageView) findViewById(R.id.Floater0);
AdPlayer0 = (VideoView) findViewById(R.id.AdPlayer);

ConvertedSource = Uri.parse("android.resource://"+ getPackageName()+ "/" + R.raw.kitkat);
AdPlayer0.setVideoURI(ConvertedSource);
AdPlayer0.start();

while (AdPlayer0.isPlaying()){
TranslateAnimation animation = new TranslateAnimation(answer, answer, 0, height * -1); // xfrom , xto, y from,y to
animation.setDuration(5000); // animation duration influences the speed of full execution
Floater0.setVisibility(View.VISIBLE); //show it
Floater0.startAnimation(animation); // start animation

}


The video plays successfully but animations do not appear, I have made sure that the animation is implemented and having correctly simply by placing it out side the braces of the loop, however this is not the aim as I want to repeatedly play animations when the video is played!

Answer
TranslateAnimation animation = new TranslateAnimation(answer,  answer, 0,  height * -1); // xfrom , xto, y from,y to
animation.setDuration(5000);
Floater0.setVisibility(View.VISIBLE); //show it
Floater0.startAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
}

@Override
public void onAnimationRepeat(Animation animation) {
}

@Override
public void onAnimationEnd(Animation animation) {
    if (AdPlayer0.isPlaying()) {
        Floater0.startAnimation(animation);
    }
}

for your video view use setOnCompletionListener for find out to video finish playing. Inside this listener stop the animation and hide the Floater0.setVisibility(View.GONE);

Comments