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"
/>
Add ImageView and Exoplayer in Framelayout. Show Image (That is knows as thumbnails) in imageView and on tap of ImageView Hide it and show ExoPlayer and play it.
Add dependency of ExoPlayer in your application. Add ExoPlayer in your layout file. In your Java/Kotlin file make a function to initialize the player. This function will initialise the ExoPlayer in the player view and it will play the media when the player is ready.
You can do it simply by creating a layout named: exo_playback_control_view. xml and override the regular XML. On this one below is the standard XML, You can add android:visiblite="invisible" for DefaultTimeBar which is what I think you're trying to hide, if not feel free change it as you want.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With