exoplayer中的自定义按钮



我想在我的exoplayer布局中添加更多按钮。我怎么能添加一个onClicklistener到我的自定义按钮的布局,这样当我点击它的变化可以在我的播放器活动产生影响?

我正在使用kotlin和数据绑定。此外,这是我的第一个应用程序,我试图使,所以我没有太多的知识。

假设您的按钮的ID为newButton,绑定对象名为mBinding,那么您可以如下设置侦听器:

mBinding.newButton.setOnClickListener { onDoSomething() }

可以在活动的onCreate()和片段的onViewCreated()中。onDoSomething()是应用程序逻辑所在的位置。

您必须重写controller_layout_id使用自定义布局如下面(带引号的行)

<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" />

你的自定义布局应该像这样(下图)

自定义布局不要忘记为每个图标使用相应的ID

<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>

最新更新