2

I've successfully added VideoView on my layout and I'm able to play it too. I have a nice animating logo on top of videoview, when certain button is clicked. In the same time I want to fade out the video. But running alpha animation on it immedietly turn it black. I found that videoview is not behaving like an ordinary view, because it's surface view. I tried putting it inside frame layout, but it didn't work. Animation looks like this:

AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
alphaAnimation.setDuration(1000);
alphaAnimation.setFillAfter(true);

videoView.suspend(); //pause video
videoView.startAnimation(alphaAnimation);

So how can I fade out video?

Makalele
  • 7,431
  • 5
  • 54
  • 81

3 Answers3

4

You cannot animate VideoView. Why don't you try using TextureView, which behaves just like a normal View. You can find how to play video in TextureView from this answer in SO.

Community
  • 1
  • 1
JiTHiN
  • 6,548
  • 5
  • 43
  • 69
  • Never heard of TextureView. But I tried it and it's working like a charm. Any animation easily works on it. – Makalele Jul 06 '15 at 22:56
4

You can make Fade Out on VideoView:

final int duration = 400;
final int colorFrom = Color.parseColor("#10000000");
final int colorTo = Color.parseColor("#000000");
ColorDrawable[] color = {new ColorDrawable(colorFrom), new ColorDrawable(colorTo)};
TransitionDrawable transition = new TransitionDrawable(color);
videoview.setBackground(transition);
transition.startTransition(duration);
maatik5
  • 148
  • 16
3

If you are using videoView it is not suitable for running aplha animation. For this you can use Exoplayer.In Exoplayer use the surface_type attribute as texture_view in xml fle and run the animation.

Eg:

 <com.google.android.exoplayer2.ui.PlayerView
            android:id="@+id/videoView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:surface_type="texture_view"
            android:animateLayoutChanges="true"/>

And your Kotlin code like this

val shortAnimationDuration = 1000
            videoView.apply {
                alpha = 0f
                animate()
                    .alpha(1f)
                    .setDuration(shortAnimationDuration.toLong())
                    .setListener(object :AnimatorListenerAdapter(){
                        override fun onAnimationEnd(animation: Animator?) {
                           //You can add what you want to do after completing animation
                        }
                    })
            }

This is a Fade in animation. If you want Fade out you just swap the alpha values.

Akhil
  • 379
  • 4
  • 14