首页 > 解决方案 > exoplayer android中的时间栏问题

问题描述

我正在尝试为 exoplayer 创建一个自定义控制器。一切正常,但我的 defaultTimeBar 有问题。我的时间栏不工作,即播放视频时看不到洗涤器头,时间栏的播放颜色也没有改变。我的自定义控制器的 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 中实现了这个控制器,如下所示:

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

谁能告诉我为什么我的时间栏不工作?为什么我还需要做?请帮我。

标签: androidkotlincustom-controlsexoplayer

解决方案


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

  • 对于播放按钮,您必须使用 idexo_play
  • 暂停是exo_pause
  • 对于搜索栏,它是exo_progress
  • 对于计时器位置,它是exo_position
  • 对于视频持续时间,它是exo_duration

使用这些 id 而不是您自己的,那么它会起作用。


推荐阅读