在视频视图android上运行alpha动画

在视频视图android上运行alpha动画,android,animation,Android,Animation,我已经成功地在我的布局中添加了VideoView,我也能播放它。当点击某个按钮时,我在videoview顶部有一个很好的动画徽标。同时,我想淡出视频。但在上面运行alpha动画会立即将其变为黑色。我发现videoview不像普通视图,因为它是表面视图。我试着把它放在框架布局中,但没用。动画如下所示: AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f); alphaAnimation.setDuration(1000); a

我已经成功地在我的布局中添加了VideoView,我也能播放它。当点击某个按钮时,我在videoview顶部有一个很好的动画徽标。同时,我想淡出视频。但在上面运行alpha动画会立即将其变为黑色。我发现videoview不像普通视图,因为它是表面视图。我试着把它放在框架布局中,但没用。动画如下所示:

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

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

那么,如何淡出视频呢?

您无法设置
视频视图的动画。为什么不尝试使用
TextureView
,它的行为与正常的
视图类似。您可以在
TextureView
中找到如何播放视频您可以在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);

如果您使用的是videoView,则它不适合运行aplha动画。为此,您可以使用Exoplayer。在Exoplayer中,使用xml fle中的“曲面类型”属性作为“纹理视图”,然后运行动画

例如:


这是一个淡入动画。如果要淡出,只需交换alpha值。

从未听说过TextureView。但我试过了,效果很好。任何动画都很容易在上面工作。
 <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
                        }
                    })
            }