调整为画中画模式时闪烁Video / SurfaceView

时间:2019-07-01 09:09:03

标签: android android-videoview exoplayer android-picture-in-picture

我正在使用我的应用中的PiP mode。实际上,它的运行情况还不错,但是我在眨眼之间就眨眼/消失了视频。

我在“全屏” /正常模式下具有VideoActivity。我正在呼叫enterPictureInPictureMode();,而Activity正在缩小到小的PiP帧。在动画结束缩小布局的那一刻,视频在一秒钟/一帧内变得透明。同样,在该帧中,整个PiP帧也会在(高程)下产生阴影。当我触摸此小PiP帧时,它会扩展到大PiP帧(而不是全屏),并且动画效果很流畅,但是当自动折叠为小PiP帧时,它最后会再次闪烁...每次{{ 1}}正在向小PiP帧添加动画(无论是从大PiP帧还是从全屏Activity崩溃),在达到最终“小界限”时都会发生一帧透明闪烁。对声音没有影响,视频播放稳定,没有对Activity的呼叫。

使用更新的API版本,我们可以创建带边界的动画,这就是我如何了解视频视图闪烁的情况……使用无属性方法会使整个布局崩溃,而我只能看到区域闪烁视频/播放器/表面视图(视频上方和下方的黑色条纹)。当我使用更新的方法和onPlayerStateChanged时,可以看到整个PiP帧消失了,而没有考虑其父级的黑色背景。实际上,我已经添加了具有固定大小,背景色和setSourceRectHint的虚拟View,例如centerInParent-它会像放置在下方的玩家一样闪烁/隐藏( PlayerView图层中的第一个,但放置在上方的位置根本不闪烁,即使在{sec.sec.sec。消失时也显示在PlayerView上方。

如何解决眨眼或设置为黑色背景而不透明的问题...

PlayerView

xml:

if (Build.VERSION.SDK_INT >= 26) {
    Rect bounds = new Rect();
    playerView.getVideoSurfaceView().getDrawingRect(bounds);
    int toTop = (playerView.getMeasuredHeight() - bounds.height()) / 2,
        toLeft = (playerView.getMeasuredWidth() - bounds.width()) / 2;
    bounds.top += toTop;
    bounds.left += toLeft;
    bounds.bottom += toTop;
    bounds.right += toLeft;
    enterPictureInPictureMode(new PictureInPictureParams.Builder().
        setSourceRectHint(bounds).
        setAspectRatio(new Rational(bounds.width(), bounds.height())).
        build());
} else
    enterPictureInPictureMode();

PS。使用在<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black"> <com.google.android.exoplayer2.ui.PlayerView android:id="@+id/activity_video_player_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerInParent="true" android:background="@android:color/black" app:controller_layout_id="@layout/exo_custom_control_view" app:fastforward_increment="10000" app:rewind_increment="10000" app:show_timeout="100" /> ... 中播放并由VideoEnabledWebChromeClient进入全屏模式的常规VideoView时,也会出现上述问题。但是在这种情况下,眨眼可以揭示WebView内容的第二部分

edit:我刚刚找到了一种使ExoPlayer闪烁的解决方法-将WebView替换为SurfaceView,添加TextureView-但我读到app:surface_type="texture_view"是一个效率降低一点,这也不能解决TextureView闪烁(VideoView的全屏显示)

edit2:可以确认Android 8(小米)和9(像素)上的闪烁

0 个答案:

没有答案