Okuhle
Okuhle

Reputation: 912

ExoPlayer - Show PlayerControlView throughout playback of audio clip

I have recently added ExoPlayer to my Android project. Setting it up, and getting an audio clip to play was relatively simple thanks to their website. I am able to get the audio file from my API and play it, but the issue is, the PlayerControlView vanishes moments after playback has started. Is there a way I can force the PlayerControlView to stay throughout playback of audio clip? Here is my XML of the fragment containing the PlayerControlView:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".SetupWizard.NewHouseInformationFragment"
android:orientation="vertical">
<TextView android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:text="@string/why_join_a_house_string"
    android:fontFamily="sans-serif-light"
    android:textColor="@android:color/black"
    android:id = "@+id/HouseDescriptionTitleTextView"
    />
<TextView
    android:id = "@+id/WhyCreateHouseTitleTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="18sp"
    android:fontFamily="sans-serif-medium"
    android:text="@string/why_create_house_string"
    android:textColor="@android:color/black"
    app:layout_constraintTop_toBottomOf="@id/HouseDescriptionTitleTextView"
    android:layout_margin="5dp"/>
<TextView
    android:fontFamily="sans-serif-light"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/manage_your_niche_network"
    android:drawableStart="@drawable/ic_check"
    android:drawablePadding="5dp"
    android:layout_margin="5dp"
    android:id = "@+id/CreateNicheNetworksTextView"
    android:textColor="@android:color/black"
    app:layout_constraintTop_toBottomOf="@id/WhyCreateHouseTitleTextView"/>
<TextView
    android:fontFamily="sans-serif-light"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@android:color/black"
    android:text="@string/share_content_string"
    android:drawableStart="@drawable/ic_check"
    android:drawablePadding="5dp"
    android:layout_margin="5dp"
    android:id = "@+id/ShareMultimediaTextView"
    app:layout_constraintTop_toBottomOf="@id/CreateNicheNetworksTextView"
    />
<TextView
    android:fontFamily="sans-serif-light"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@android:color/black"
    android:text="@string/send_broadcasts_messages"
    android:id = "@+id/SendBroadcastsTextView"
    android:layout_margin="5dp"
    android:drawableStart="@drawable/ic_check"
    android:drawablePadding="5dp"
    app:layout_constraintTop_toBottomOf="@id/ShareMultimediaTextView"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    />
<ImageView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id = "@+id/NewHouseContentImage"
    app:layout_constraintTop_toBottomOf="@id/FullControlTextView"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintVertical_weight="1"
    android:layout_margin="5dp"
    app:srcCompat = "@drawable/ic_chatting"
    android:adjustViewBounds="true"
    app:layout_constraintBottom_toTopOf="@id/CreateHousePlayerView"/>
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/be_your_own_boss"
    android:textColor="@android:color/black"
    android:fontFamily="sans-serif-light"
    android:drawableStart="@drawable/ic_check"
    app:layout_constraintTop_toBottomOf="@id/SendBroadcastsTextView"
    android:layout_margin="5dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:drawablePadding="5dp"
    android:id = "@+id/FullControlTextView"/>
<com.google.android.exoplayer2.ui.PlayerControlView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    android:id = "@+id/CreateHousePlayerView"
    android:layout_margin="5dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    />

Upvotes: 8

Views: 5749

Answers (1)

Okuhle
Okuhle

Reputation: 912

After taking a close look at documentation, I found this information:

The following attributes can be set on a PlayerControlView when used in a layout XML file:

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.

So, I went into my PlayerControlView and set the show_timeout attribute to zero. Now the player control view does not disappear after some time.

<com.google.android.exoplayer2.ui.PlayerControlView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:show_timeout="0"
    app:layout_constraintBottom_toBottomOf="parent"
    android:id = "@+id/CreateHousePlayerView"
    android:layout_margin="5dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@id/NewHouseContentImage"
    />

Source: https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/ui/PlayerControlView.html

Upvotes: 11

Related Questions