5

I have a PlayerView that takes up the top half of the Fragment in portrait orientation with the bottom half showing some text. The fragment is a part of a ViewPager and a user can switch screens with different videos.

Problem: While navigating between screens (swiping right/left) the PlayerView sometimes shows a preview image from the previous screen. It is shown just for a fraction of a second and then it shows the correct preview picture, but it is noticeable.

Question: How do I make the PlayerView show only the correct preview picture? It shouldn't blink with the previous picture. May be I'm misusing something (wrong instantiation of the Player or the View...)? May be some workaround if it is a known issue(blurring the video while swiping, etc)? Any suggestion/idea is appreciated.

Here is how my layout looks like:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/video_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_below="@id/video_view"
        android:scrollbars="vertical" />

</RelativeLayout>

In Fragment code I have:

@Override
public void onStart() {
    ...
    SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(
            getActivity(), new DefaultTrackSelector()
    );
    player.prepare(mediaSource);
    playerView.setPlayer(player);
    ...
}

EDIT 1.

As requested in the comments section my PageAdapter is pretty standard (just like the one Android Studio generates while creating a Tabbed Activity) with the only extension - I save current fragment in it just like it is suggested here.

Sasha Shpota
  • 9,436
  • 14
  • 75
  • 148

0 Answers0