I'd like to add more buttons to my exoplayer layout. How can I add an onClicklistener to my custom button in the layout so that when I click on it changes can take affect in my player activity?
I'm using kotlin and databinding. Also this is my first app that I'm trying to make so I haven't much knowledge.
CodePudding user response:
Assuming your button has an ID newButton
, and the binding object is called mBinding
, then you can set up the listener as follow:
mBinding.newButton.setOnClickListener { onDoSomething() }
This can either be inside the onCreate()
for an activity and onViewCreated()
for a fragment.
onDoSomething()
is where the application logic goes.
CodePudding user response:
You will have to override controller_layout_id with your custom layout like below (the quoted line)
<com.google.android.exoplayer2.ui.PlayerView
android:id="@ id/exoplayer_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
app:controller_layout_id="@layout/custom_layout"
app:fastforward_increment="10000"
app:hide_on_touch="true"
app:player_layout_id="@layout/exo_player_view"
app:resize_mode="fit"
app:rewind_increment="10000"
app:show_timeout="4000"
app:shutter_background_color="#000000"
app:surface_type="surface_view"
app:use_controller="true" />
Your custom layout should be something like this (the image below)
Don't forget to use corresponding ID's for each Icon
<drawable name="exo_controls_play">@drawable/exo_icon_play</drawable>
<drawable name="exo_controls_pause">@drawable/exo_icon_pause</drawable>
<drawable name="exo_controls_next">@drawable/exo_icon_next</drawable>
<drawable name="exo_controls_previous">@drawable/exo_icon_previous</drawable>
<drawable name="exo_controls_fastforward">@drawable/exo_icon_fastforward</drawable>
<drawable name="exo_controls_rewind">@drawable/exo_icon_rewind</drawable>
<drawable name="exo_controls_repeat_all">@drawable/exo_icon_repeat_all</drawable>
<drawable name="exo_controls_repeat_off">@drawable/exo_icon_repeat_off</drawable>
<drawable name="exo_controls_repeat_one">@drawable/exo_icon_repeat_one</drawable>
<drawable name="exo_controls_shuffle_off">@drawable/exo_icon_shuffle_off</drawable>
<drawable name="exo_controls_shuffle_on">@drawable/exo_icon_shuffle_on</drawable>
<drawable name="exo_controls_fullscreen_enter">@drawable/exo_icon_fullscreen_enter</drawable>
<drawable name="exo_controls_fullscreen_exit">@drawable/exo_icon_fullscreen_exit</drawable>
<drawable name="exo_controls_vr">@drawable/exo_icon_vr</drawable>