Vikas Acharya
Vikas Acharya

Reputation: 4152

how to always show progress bar and time in exoplayer

I'm trying to show the progress bar always in exoplayer. My view looks like this and I used custom ui for player.

<com.google.android.exoplayer2.ui.PlayerView
                android:id="@+id/id_player_view"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:background="@android:color/darker_gray"
                android:src="@android:drawable/ic_media_play"
                app:controller_layout_id="@layout/custom_exoplayer_controller"
                app:fastforward_increment="5000"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:resize_mode="fixed_height"
                app:rewind_increment="5000"
                app:use_controller="true">

the below custom component I always wanted to show.

<LinearLayout
        android:id="@+id/progressbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignWithParentIfMissing="false"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="false"
        android:layout_centerVertical="false"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:gravity="center_vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <TextView
            android:id="@id/exo_position"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:includeFontPadding="false"
            android:paddingLeft="4dp"
            android:paddingRight="4dp"
            android:text="00:00"
            android:textColor="#FFBEBEBE"
            android:textSize="14sp"
            android:textStyle="bold" />

        <com.google.android.exoplayer2.ui.DefaultTimeBar
            android:id="@id/exo_progress"
            android:layout_width="0dp"
            android:layout_height="26dp"
            android:layout_weight="1"
            app:played_color="#4589f2" />

        <TextView
            android:id="@id/exo_duration"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:includeFontPadding="false"
            android:paddingLeft="4dp"
            android:paddingRight="4dp"
            android:text="2:00:00"
            android:textColor="#FFBEBEBE"
            android:textSize="14sp"
            android:textStyle="bold" />

    </LinearLayout>

But the media controller and progress bar will be hidden If screen is untouched for 5 seconds or so by default.

how to achieve this ?

Upvotes: 2

Views: 2938

Answers (2)

Yuan
Yuan

Reputation: 35

show_timeout="0"

From the documentation:

show_timeout - The time between the last user interaction and the controls being automatically hidden, in milliseconds. Use zero if the controls should not automatically timeout.

  • Corresponding method: setShowTimeoutMs(int)
  • Default: DEFAULT_SHOW_TIMEOUT_MS

Source: https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/ui/PlayerControlView.html

Upvotes: 0

Daniel Knauf
Daniel Knauf

Reputation: 589

You have to set controllerShowTimeoutMs to -1 to prevent the controller from disappearing automatically.

From method docs:

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.

Upvotes: 1

Related Questions