Reputation: 7521
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?
Upvotes: 2
Views: 5988
Reputation: 329
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"/>
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.
Upvotes: 3
Reputation: 277
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);
Upvotes: 4
Reputation: 6588
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.
Upvotes: 4