android - exoplayer android 中的时间栏问题

标签 android kotlin custom-controls exoplayer

我正在尝试为 exoplayer 创建自定义 Controller 。一切工作正常,但我的 defaultTimeBar 有问题。我的时间栏不起作用,即播放视频时看不到洗涤器头,并且时间栏的播放颜色也没有改变。我的自定义 Controller 的 xml 代码如下所示:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp">

<LinearLayout
    android:orientation="horizontal"
    android:id="@+id/llSeekBar"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:padding="8dp"
    android:gravity="center_vertical|center_horizontal"
    android:layout_marginBottom="8dp"
    android:background="@drawable/controller_background"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/imvPlay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:src="@drawable/ic_play" />

    <TextView
        android:id="@+id/txvStartDuration"
        android:text="24:24"
        android:layout_gravity="center"
        android:textColor="@color/white"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

     <com.google.android.exoplayer2.ui.DefaultTimeBar
        android:id="@+id/defaultTimeBar"
        android:layout_gravity="center"
        android:layout_weight="4"
        app:buffered_color="@color/white"
        app:played_color="@color/red"
        app:unplayed_color="@color/blue"
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>

    <TextView
        android:id="@+id/txvDurationLeft"
        android:text="24:24"
        android:layout_gravity="center"
        android:textColor="@color/white"
        android:layout_width="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_height="wrap_content"/>
</LinearLayout>

</RelativeLayout>

我已在我的 videoLayout 中实现了此 Controller ,如下所示:

<com.google.android.exoplayer2.ui.PlayerView
         android:id="@+id/todayVideo"
         app:player_layout_id="@layout/exo_styled_player_view"
          app:controller_layout_id="@layout/custom_controller"
          app:use_controller="true"
          app:resize_mode="fit"
          android:background="@color/black"
          app:hide_on_touch="true"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:show_buffering="always" />

有人可以告诉我为什么我的时间栏不起作用吗?我还需要做什么?请帮助我。

最佳答案

Exoplayer Controller 在其默认实现中具有预定义的 id,要制作自定义 Controller ,您必须为每个组件提供与默认实现完全相同的 id。

  • 对于播放按钮,您必须使用 id exo_play
  • 暂停是exo_pause
  • 对于搜索栏,它是 exo_progress
  • 对于计时器位置,它是 exo_position
  • 视频时长为 exo_duration

使用这些 ID 而不是您自己的 ID,这样就可以了。

关于android - exoplayer android 中的时间栏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68017241/

相关文章:

java - 了解 Android 中的 Runnable

android - 如何使用appium自动化android手机后退按钮

java - 将 Kotlin IntArray 转换为 ValueAnimator 所需的 Java Object[]

c# - 仅更改月份和年份的 DateTimePicker

html - 如何强制我的自定义样式?

c++ - 如何在基于对话框的 MFC 项目上创建自定义控件 (visual studio 2012)

android - 在使用 tensorflow 模型时,我们可以使用 .pbtxt 而不是 .pb 文件吗

java - android 窗口软输入模式

list - 如何在 Kotlin 中从另一个列表创建新列表?

android - 如何避免 Kotlin 中同名冲突的类型?