Android - 将标题传递给ExoPlayer的自定义布局



在我的Android应用程序中,我有一个自定义布局为我的PlayerView:

<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:use_controller="true"
app:resize_mode="fill"
app:controller_layout_id="@layout/exo_player_control_view"/>

你可以看到自定义布局叫做exo_player_control_view.xml,它包含播放&stop图标+一个TextView作为视频的标题:

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="test"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<ImageView
android:id="@id/exo_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/play"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<ImageView
android:id="@id/exo_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pause"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>

它工作得很好,但我的问题是:我怎么能在运行时传递视频的标题到TextView。在我的应用程序中,用户从列表中选择一个视频项目,我让它在一个包含PlayerView布局的新片段中播放。但是我不知道如何将视频项目的标题传递给自定义布局exo_player_control_view.xml。通常情况下,我会用数据绑定来做,但我不知道在这种情况下如何做。

在野外有一些SO线程,但没有一个是有用的。

您应该能够像这样使用findViewById找到视图:mySimpleExoPlayerView.findViewById(R.id.title)

最新更新