How to remove Next and Previous button from SimpleExoPlayerView in Android

I am using ExoPlayer to play audio in my Android application with SimpleExoPlayerView as a controller. By default, the controller has five buttons: Play / Pause, Forward, Back, Next, and Previous. My application uses only Play / Pause, Forward and Backward, so I want to remove the Next and Previous buttons from the controller, but I could not find how to do this using SimpleExoPlayerView. How to achieve this?

+9
source share
4 answers

You will need an exo_playback_control_view.xml file with a custom layout that looks exoplayer by default to inflate the look of control. It is important that the custom layout is called exo_playback_control_view and id used

The default controls can be seen in the source code here release-v2 or here dev-v2-r2.3.1 (make sure you find the version of exoplayer that you are using)

You can copy this file to the res/layout directory and delete the unwanted buttons, this is what the default looks like:

 <ImageButton android:id="@id/exo_prev" style="@style/ExoMediaButton.Previous"/> <ImageButton android:id="@id/exo_rew" style="@style/ExoMediaButton.Rewind"/> <ImageButton android:id="@id/exo_play" style="@style/ExoMediaButton.Play"/> <ImageButton android:id="@id/exo_pause" style="@style/ExoMediaButton.Pause"/> <ImageButton android:id="@id/exo_ffwd" style="@style/ExoMediaButton.FastForward"/> <ImageButton android:id="@id/exo_next" style="@style/ExoMediaButton.Next"/> 


There is also a post on the media, which is a great help for configuring exoplayer ; The author writes a custom control:
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageButton android:id="@id/exo_play" android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center" android:background="#CC000000" style="@style/ExoMediaButton.Play"/> <ImageButton android:id="@id/exo_pause" android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center" android:background="#CC000000" style="@style/ExoMediaButton.Pause"/> </FrameLayout> 

Please note that id is required

+11
source

There are default styles for each button. Just redefine the styles of the Previous and Next buttons and add the visibility faded.
Put below styles in your style.xml

 <style name="ExoMediaButton.Previous"> <item name="android:visibility">gone</item> </style> <style name="ExoMediaButton.Next"> <item name="android:visibility">gone</item> </style> 
+18
source

You must hideControl() , I will do it too.

  • Create a CustomSimpleExoPlerView as a SimpleExoPlayerView .
  • Comment all lines have showControl() .
  • Install CustomSimpleExoPlayer in xml.
0
source

Note that button visibility changes dynamically
So it’s better to set them to zero to completely hide

  <ImageButton android:id="@id/exo_prev" android:layout_width="0dp" android:layout_height="0dp" style="@style/ExoMediaButton.Previous" android:visibility="gone"/> <ImageButton android:id="@id/exo_rew" style="@style/ExoMediaButton.Rewind"/> <ImageButton android:id="@id/exo_shuffle" style="@style/ExoMediaButton.Shuffle" android:visibility="gone"/> <ImageButton android:id="@id/exo_repeat_toggle" style="@style/ExoMediaButton" android:visibility="gone"/> <ImageButton android:id="@id/exo_play" style="@style/ExoMediaButton.Play"/> <ImageButton android:id="@id/exo_pause" style="@style/ExoMediaButton.Pause"/> <ImageButton android:id="@id/exo_ffwd" style="@style/ExoMediaButton.FastForward"/> <ImageButton android:id="@id/exo_next" android:layout_width="0dp" android:layout_height="0dp" style="@style/ExoMediaButton.Next" android:visibility="gone"/> <ImageButton android:id="@+id/exo_fullscreen" android:src="@drawable/fullscreen" style="@style/ExoMediaButton"/> <ImageButton android:id="@+id/exo_vr" style="@style/ExoMediaButton" android:visibility="gone"/> 
0
source

Source: https://habr.com/ru/post/1267216/


All Articles