** I really need help if you don\'t know anything don\'t give me a negative point :| if something bother you comment**
I want to write custom UI for my player in Exo
ok, that took me half a day, until i didn't dive into the library code and found such text:
To customize the layout of PlaybackControlView throughout your app, or just for certain configurations, you can define exo_playback_control_view.xml layout file in your application res/layout directories. These layouts will override the one provided by the ExoPlayer library, and will be inflated for use by PlaybackControlView.
Full text: https://github.com/google/ExoPlayer/blob/release-v2/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlaybackControlView.java
Also, want to add that u can specify custom layout in PlayerView like so:
<com.google.android.exoplayer2.ui.SimpleExoPlayerView android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:controller_layout_id="@layout/custom_controls"/>
Actually the code of involking play & pause methods are in class PlayerControl.
If you don't want to use default Android media controller UI, just don't use the MediaController
class, create your own UI in your layout file with custom play & pause button and bind the actions with the button's onClickListener.
To play the video, call exoPlayer.setPlayWhenReady(true);
And to pause: call exoPlayer.setPlayWhenReady(false);
It's similar problem with how to create custom UI for android MediaController
Customizing the ExoPlayer's UI is pretty simple. If you look at the ExoPlayer source, the layout res directory contains the file exo_player_control_view.xml
that points to (includes) another layout - exo_playback_control_view
.
exo_playback_control_view.xml
custom_exo_playback_control_view.xml
. Paste the copied contents to the new xmlPlayerView
.Here is the custom_exo_controller_view
xml that I created from the original. I wanted a different background color for the player controls and different button and progress view colors:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/attachment_document_desc_bg"
android:layoutDirection="ltr"
android:orientation="vertical"
android:paddingStart="20dp"
android:paddingEnd="20dp"
tools:targetApi="28">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="4dp">
<ImageButton
android:id="@id/exo_prev"
style="@style/ExoMediaButton.Previous"
android:tint="@color/colorPrimaryDark"
android:tintMode="src_in" />
<ImageButton
android:id="@id/exo_rew"
style="@style/ExoMediaButton.Rewind"
android:tint="@color/colorPrimaryDark"
android:tintMode="src_in" />
<ImageButton
android:id="@id/exo_shuffle"
style="@style/ExoMediaButton.Shuffle"
android:tint="@color/colorPrimaryDark"
android:tintMode="src_in" />
<ImageButton
android:id="@id/exo_repeat_toggle"
style="@style/ExoMediaButton"
android:tint="@color/colorPrimaryDark"
android:tintMode="src_in" />
<ImageButton
android:id="@id/exo_play"
style="@style/ExoMediaButton.Play"
android:tint="@color/colorPrimaryDark"
android:tintMode="src_in" />
<ImageButton
android:id="@id/exo_pause"
style="@style/ExoMediaButton.Pause"
android:tint="@color/colorPrimaryDark"
android:tintMode="src_in" />
<ImageButton
android:id="@id/exo_ffwd"
style="@style/ExoMediaButton.FastForward"
android:tint="@color/colorPrimaryDark"
android:tintMode="src_in" />
<ImageButton
android:id="@id/exo_next"
style="@style/ExoMediaButton.Next"
android:tint="@color/colorPrimaryDark"
android:tintMode="src_in" />
<ImageButton
android:id="@id/exo_vr"
style="@style/ExoMediaButton.VR"
android:tint="@color/colorPrimaryDark"
android:tintMode="src_in" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<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:textColor="#ff323232"
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="@color/colorPrimaryDark"
app:unplayed_color="@color/gray" />
<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:textColor="#ff323232"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
Below is the code that I use for the player. Notice, the xml attribute app:controller_layout_id
points to the custom controller view thats defined above.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:auto_show="true"
app:controller_layout_id="@layout/custom_exo_controller_view"
app:fastforward_increment="10000"
app:repeat_toggle_modes="none"
app:resize_mode="fixed_width"
app:rewind_increment="10000"
app:surface_type="surface_view"
app:use_controller="true" />
</FrameLayout>
That should get the UI the way you want.
You can add extra controls as you need in the custom controller and in your code, find the control with findViewById()
and write event listeners, etc.