chowey
chowey

Reputation: 9826

ExoPlayer: How to tell if controls are showing?

I'm using ExoPlayer for an Android app, and I want to toggle the visibility of the controls.

I see that PlayerView has a showController() method and a hideController() method, but no toggleController() method.

Obviously I can implement toggleController() myself, but how do I tell if the controls are visible? I am specifying a custom controller layout with something like this:

<com.google.android.exoplayer2.ui.PlayerView
    android:id="@+id/player_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:controller_layout_id="@layout/exo_controls" />

and I need to figure out a function like this (e.g. in Kotlin):

fun toggleController() {
    val playerView = findViewById<PlayerView>(R.id.player_view)
    val controlsVisible = // ???
    if (controlsVisible) {
        playerView.hideController()
    } else {
        playerView.showController()
    }
}

Upvotes: 2

Views: 3290

Answers (2)

redPanda
redPanda

Reputation: 797

All you need to do is call isControllerVisible() on your PlayerView:

            if (mPlayerView.isControllerVisible()) {
                // Do something if controls are visible
                return true;
            } else {
                // Do something else if controls are not showing
                return false;
            }

Upvotes: 6

RyanCheu
RyanCheu

Reputation: 3552

You can just store whether the controls are currently visible and change it every time the controls are hidden or shown. You'll probably want to rate limit your toggle to avoid double animation issues.

Upvotes: 1

Related Questions