sna*_*msm 6 android android-videoview exoplayer android-picture-in-picture
我正在我的应用程序中使用画中画模式。事实上,它工作得很好,但我在瞬间闪烁/消失视频时遇到了问题。
我在“全屏”/正常模式下有 VideoActivity。我正在打电话enterPictureInPictureMode();并且Activity正在崩溃到小的画中画帧。在动画结束缩小布局的那一刻,视频会在一瞬间/一帧内变得透明。同样在这个框架中,整个画中画框架在(高度)下都有阴影。当我触摸这个小画中画帧时,它会扩展到大画中画帧(不是全屏)并且这个动画很流畅,但是当自动折叠到小画中画帧时它会在最后再次闪烁......每次Activity动画时到小画中画帧(无论是从大画中画帧还是全屏折叠Activity),当达到最终“小边界”时,会发生一帧透明闪烁。对声音无影响,视频播放稳定,无来电onPlayerStateChanged。
使用较新的 API 版本,我们可以创建有边界的动画,这就是我知道视频视图正在闪烁的方式......使用无属性方法使整个布局折叠,我只能在视频/播放器/表面视图(黑色条纹)区域看到闪烁上面和下面的视频)。当我使用较新的方法时,setSourceRectHint我可以看到整个画中画帧消失,而不考虑其父级的黑色背景。实际上,我添加了View具有固定大小、背景颜色centerInParent等的虚拟对象PlayerView- 当放置在(父级中的第一个)PlayerView层下方时,它会像玩家一样闪烁/隐藏,但放置在上方根本不闪烁,PlayerView即使在它上方显示消失一秒。
如何修复闪烁或设置黑色背景,而不是透明...
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();
Run Code Online (Sandbox Code Playgroud)
xml:
<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" />
...
Run Code Online (Sandbox Code Playgroud)
附注。当使用通常VideoView播放WebView并通过VideoEnabledWebChromeClient进入全屏时,也会出现上述问题。但在这种情况下,眨眼会显示WebViews 内容的一瞬间
编辑:我刚刚找到了一种使 ExoPlayer 闪烁的解决方法 - 通过替换SurfaceView为TextureView,添加app:surface_type="texture_view"- 但我正在阅读它的TextureView效率有点低,而且这也不能修复VideoView闪烁(全屏从WebView)
编辑 2:可以确认在 Android 8(小米)和 9(像素)上闪烁
| 归档时间: |
|
| 查看次数: |
1101 次 |
| 最近记录: |