Exoplayer: Allow Animation for PlaybackControlView

Created on 1 Jan 2017  路  12Comments  路  Source: google/ExoPlayer

I want to be able to add animation to PlaybackControlView, however it looks like it is not possible,

I tried simpleExoPlayerView.setAnimation(fadeOut) but it does not work.

Is there another solution?

enhancement low priority

Most helpful comment

probably no need to change anything inside library

<com.google.android.exoplayer2.ui.SimpleExoPlayerView android:animateLayoutChanges="true" ... />

adding animateLayoutChanges gave me fade in/ fade our for free.

All 12 comments

The view is made up of multiple elements, so it's not really clear from your description what you're trying to do. What kind of animation are you trying to add, and which parts of the view do you expect it to apply to?

If you're attempting to apply a simple fade in/out to all of the playback controls, then I can see that as something we should reasonably support. If you're trying to do something more complicated than that, you'll likely need to implement your own view.

Please clarify; thanks!

Thank you for taking the time to reply.

So here more details and what I achieved so far.

I want to make a simple fadein fadeout. I created a custom ui exo_playback_control_view.xml, and added different views. So I wanted to be able to fade-in, fade-out on all this, basically all the control elements.

So far I successfully implemented fadein, by listening for a visibility change and adding the animation on the FrameLayout. Fadeout is impossible using this approach, because when the listener is triggered, the controls will disappear instantly.

Do you have any idea whether doing the fadein and fadeout is possible currently, and how? or will it need a change in the source.

It will need a source change.

Are their any plans to support this?

Would a solution like allowing a R.id.exo_controller element to override the controller be valid?
That way you could switch out R.id.exo_controller_placeholder with the default PlaybackControlView if the element is available, use the user PlaybackControlView extending class if R.id.exo_controller exists, or just render no controls if neither element exists.

Happy to make a PR for the above if that sounds like a valid work around. It would work for me, as the hide() and show() methods and PlaybackControlView are not final. So I could kick off the animation there then call super to finalise the hide etc.

Do you also want this specifically for fade in/out, or something more advanced? As per above, it feels like we should just add fade in/out support directly to the library view. We're not likely to get around to this any time soon, but would accept a good quality pull request that adds support! Thanks.

@dbrain - The PR you sent also looks like a good addition. I'll get that merged. We should still support fade in/out directly though!

@ojw28 Thanks. We were going to fiddle with a slide/fade in or just a fade, depending on how it felt in the app. So the overridable PlaybackControlView suits our needs better.

I'll have a fiddle with adding fade support to the PlaybackControlView itself in the next few days. Would be a good addition. Most of the time that would be enough to make everyone happy.

I solve this problem (in Kotlin):

    simpleExoPlayerView.setControllerVisibilityListener { visibility ->
        val layout = activity.findViewById<LinearLayout>(R.id.ll_customPlayBackControlView)

        if (layout.tag != "IN_ANIMATION") {
            when (visibility) {
                View.GONE -> {
                    layout.tag = "IN_ANIMATION"
                    ex_fragmentVideoView.showController()
                    layout.animate().alpha(0F).setDuration(450L).withEndAction({ ex_fragmentVideoView.hideController(); layout.tag = "" }).start()
                }
                View.VISIBLE -> {
                    layout.animate().alpha(1F).setDuration(450L).start()
                }
            }
        }
    }

@marcelomourasouza this only works partially, if you want the controls visible again you need to tap the view 2 times.

probably no need to change anything inside library

<com.google.android.exoplayer2.ui.SimpleExoPlayerView android:animateLayoutChanges="true" ... />

adding animateLayoutChanges gave me fade in/ fade our for free.

Closing because it seems the simple case is supported, as per Yura's comment above. For more complicated cases, it's hard to predict what developers would want in order to provide a general solution. For those cases developers will likely need to implement their own UI components.

Was this page helpful?
0 / 5 - 0 ratings