I have an Exoplayer view in a fragment, when I animate the fragment container view from the activity the exo player will become black.
I used setKeepContentOnPlayerReset(true);
to keep the last frame and it's working fine.
But when I call the animate (sliding animation) on fragment container view (that's a Frame Layout) after the video is over, Exo player will display the black screen. (even the fragment exit transition also creates the same issue on Exo player, this time I didn't replaced the fragment just animated the container view, the issue is still present)
I haven't any clue related to this issue, It would be very helpful if anyone can share some idea related to this. welcomes every suggestion and answers related to this. Thank you.
Asked
Active
Viewed 3,287 times
3

Renjith K N
- 2,613
- 2
- 31
- 53
2 Answers
7
It's turned out that using "texture_view
" for "app:surface_type
" will resolve the issue, This will make the Exo player use texture view instead of the surface view and that makes animations and scrolling smooth.
In documentation its says
On earlier releases, this could result in unwanted effects when a SurfaceView was placed into a scrolling container, or when it was subjected to animation. Such effects included the SurfaceView’s contents appearing to lag slightly behind where it should be displayed, and the view turning black when subjected to animation
In xml file, we can enable texture view as follows
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/playerView"
android:layout_width="match_parent"
android:layout_height="200dp"
app:surface_type="texture_view"/>

Renjith K N
- 2,613
- 2
- 31
- 53
-
i want to add right and left swipe Gesture animation (Like a view pager ). – Vikas Nov 06 '20 at 16:05
-
This resolves the black BG issue while coming from pause to resume the state of activity. Awesome. – Faldu Jaldeep Aug 02 '22 at 06:34
-1
You can use this 2 solutions...
add this attribute to PlayerView :
app:surface_type="texture_view"
use this in your code :
val simpleExoPlayer = SimpleExoPlayer.Builder(requireContext()) .setMediaSourceFactory( DefaultMediaSourceFactory(requireContext()) ) .build() simpleExoPlayer.addAnalyticsListener(object : AnalyticsListener { override fun onSurfaceSizeChanged( eventTime: AnalyticsListener.EventTime, width: Int, height: Int ) { super.onSurfaceSizeChanged(eventTime, width, height) val surfaceView = playerView.videoSurfaceView if (surfaceView is SurfaceView) { surfaceView.holder.setFixedSize(width, height) } } })

marc_s
- 732,580
- 175
- 1,330
- 1,459

farshad rezaei
- 79
- 5