Reputation: 318
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!
Upvotes: 0
Views: 618
Reputation: 655
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);
Upvotes: 1
Reputation: 2346
I think you just need to remove the while (AdPlayer0.isPlaying()){
add animation.setRepeatCount(Animation.INFINITE);
and on
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation arg0) {
Floater0.stopAnimation(animation);
}
Upvotes: 1
Reputation: 2117
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
}
Maybe the video don't have time to load, after the start your are directly calling the while, but isPlaying should return false maybe as the video is not started yet. Moreover in your while block your creating a new animation, it will result to create multiple animation when the video is still playing...
Upvotes: 1