How do I make the Exoplayer controls always visible?
Asked Answered
C

5

17

A few seconds after the ExoPlayer starts playing, the controls stop showing and a black background appears. How do I make sure that the controls are always visible?

Camshaft answered 19/11, 2017 at 18:42 Comment(0)
K
20

Set show_timeout attribute to 0

Krishnakrishnah answered 19/11, 2017 at 18:52 Comment(2)
on touch of player, it will hide controller, mPlayerView.setControllerHideOnTouch(false) user this to prevent controller to hideTacitus
xml equivalent or Player.setControllerHideOnTouch(false) is app:hide_on_touch="false"Mccormac
E
4

You can do it programmatically using these,

    PlayerView.setControllerShowTimeoutMs(0);
    PlayerView.setControllerHideOnTouch(false);
Eugenieeugenio answered 16/8, 2020 at 6:30 Comment(0)
P
3

Just posting for someone how needs, Try this once.

Please add below 2 lines in the XML view.

 app:show_timeout="0"
 app:hide_on_touch="false"

Like full Example.

<com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/audio_view"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:isScrollContainer="false"
        app:controller_layout_id="@layout/exo_playback_control_view_audio"
        app:fastforward_increment="10000"
        app:show_timeout="0"
        app:hide_on_touch="false"
        app:resize_mode="fill"
        app:rewind_increment="10000"
        app:show_buffering="always" />
Paulson answered 2/7, 2020 at 15:58 Comment(0)
Z
0

If you see the below method in SimpleExoPlayerView class, you need to provide negative value in order for the controls to visible always.

/**
* Sets the playback controls timeout. The playback controls are automatically hidden after this
* duration of time has elapsed without user input and with playback 
  or buffering in progress.
* @param controllerShowTimeoutMs The timeout in milliseconds. A non-
  positive value will cause the controller to remain visible indefinitely.
*/
public void setControllerShowTimeoutMs(int controllerShowTimeoutMs) {
       Assertions.checkState(controller != null);
       this.controllerShowTimeoutMs = controllerShowTimeoutMs;
}
Zoom answered 21/12, 2017 at 6:23 Comment(0)
S
0

The other answers are correct to keep the player always visible (not hide automatically after a certain time):

// Programmatically
playerView.controllerShowTimeoutMs = 0
playerView.controllerHideOnTouch = false


// Equivalent XML
app:show_timeout="0"
app:hide_on_touch="false"

But, if those will not work for making it initially visible, for instance if the player is not already initialized/playing or in case you came back to the app after clearing it out from the recent apps while the player is still playing in background. In such cases the player controls will be hidden. To fix those cases you need to call showController()

playerView.showController()
Scrawly answered 2/11, 2023 at 5:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.