GauthierChan / ExoPlayerBlackBlink

Test project to show the the delay between the ExoPlayer telling us the video is ready and the first frame being shown
0 stars 0 forks source link

Was this solved somehow? #1

Open AndroidDeveloperLB opened 5 years ago

AndroidDeveloperLB commented 5 years ago

I've read this: https://github.com/google/ExoPlayer/issues/3870

I'm having a similar issue for some reason, which I couldn't reproduce on POC.

I am switching between fragments, and one of them has the PlayerView which should play right away, but it has a point that it shows a black content. I tried to use what's written on this post, along with having an ImageView that shows the first frame (image and video files are built into the app) which gets hidden when the onPlayerStateChanged is called with STATE_READY.

Still, when switching from/to the fragment that has the PlayerView, it has black/white glitches...

The only workaround I got is to use a Handler, as such:

                player!!.addListener(object : Player.EventListener {
                    override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
                        if (playbackState == Player.STATE_ENDED || playbackState == Player.STATE_READY)
                            player!!.removeListener(this)
                        if (playbackState == Player.STATE_READY)
                        //WORKAROUND for black/white glitches when switching between states of playback
                            Handler().postDelayed({ rootView.playerOverlayBackgroundView.visibility = View.INVISIBLE }, 200L)
                    }
                })

Together with this in the layout file (the ImageView is on top of the PlayerView, entirely) :

        <com.google.android.exoplayer2.ui.PlayerView
            android:id="@+id/playerView" android:layout_width="0px" android:layout_height="0px"
            android:layout_marginBottom="20dp" android:layout_marginTop="16dp" app:keep_content_on_player_reset="true"
            app:layout_constraintBottom_toTopOf="@id/createClipButton" app:layout_constraintDimensionRatio="420:660"
            app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/descTextView"
            app:shutter_background_color="#00000000" app:surface_type="texture_view"
            app:use_controller="false" tools:foreground="#33ff0000"/>

        <ImageView
            android:id="@+id/playerOverlayBackgroundView" android:layout_width="0px" android:layout_height="0px"
            android:background="#fff" android:src="@drawable/first_frame"
            app:layout_constraintBottom_toBottomOf="@id/playerView" app:layout_constraintEnd_toEndOf="@id/playerView"
            app:layout_constraintStart_toStartOf="@id/playerView" app:layout_constraintTop_toTopOf="@id/playerView"/>

I was wondering: Did you solve this issue somehow?

GauthierChan commented 5 years ago

Using a TextureView was definitely an improvement from the SurfaceView, the black blink was shorter. But I ended up doing just like you, adding a 100 ms delayed Handler to hide the placeholder.

It was acceptable for our use case, but yeah the issue still exists.

AndroidDeveloperLB commented 5 years ago

Do you have perhaps a POC that reproduces the issue, even after all the recommendation of them? I want to raise it again, and tell them to fix it... I've failed to reproduce it for some reason, but maybe it's because the POC isn't similar enough to what we do on the real app... I hate to see a workaround of a handler, let alone with a time in it...

GauthierChan commented 5 years ago

Just tried this repo, and yeah it seems like having 2 different Activities makes it work.

It happens on our production app when we're adding/replacing Fragments though(which seems to be your case too). The first time the ExoPlayer is shown it will not blink, but any other time it will. I can't update this repo with our production code easily though. I'll update this issue when I'll get some time.

AndroidDeveloperLB commented 5 years ago

Wow thank you.

In our case, the app has BottomNavigationView, that when you switch between the pages there, in one of them there is a ViewPager with one of its inner fragments with the player. I just wrote "I am switching between fragments" because I didn't want to confuse you and give too much useless information... I'm sure it doesn't have to be this complex for a POC to reproduce it, but the basic thing I tried on POC wasn't enough.