ExoPlayer 在视频播放期间不显示 play/pause

ExoPlayer is not showing play/pause during video playback

我正在开发将使用 ExoPlayer 播放视频的应用程序。出于某种原因,当我尝试暂停视频播放器时,它没有显示 play/pause 图标。我只为 play/pause 制作了自定义布局并将其设置在 PlayerView 上。 Playing/pause 视频 player.playWhenReady = trueplayer.playWhenReady = true。到处都找不到解决方案,看起来我错过了什么但不知道是什么。

custom_player_controller.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageButton android:id="@id/exo_play"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:background="#CC000000"
        style="@style/ExoMediaButton.Play"/>

    <ImageButton android:id="@id/exo_pause"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:background="#CC000000"
        style="@style/ExoMediaButton.Pause"/>

</FrameLayout>

我在 RecyclerView 中使用 ExoPlayer,这里是 layout_item.xml for RecyclerView

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:focusable="true">

    <com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/feed_video_player"
        app:surface_type="texture_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:resize_mode="fixed_width"
        app:controller_layout_id="@layout/custom_player_controller"
        android:paddingBottom="55dp"
        android:background="#000"/>

</RelativeLayout>

然后 play/pause RVAdapter 中的视频我正在这样做

setOnTouchListener(object : View.OnTouchListener {
    val gestureDetector: GestureDetector = GestureDetector(context, object:
        GestureDetector.SimpleOnGestureListener() {

        override fun onSingleTapUp(e: MotionEvent?): Boolean {
            super.onSingleTapUp(e)

            if (!player.playWhenReady) {
                player.playWhenReady = true
            } else {
                player.playWhenReady = false
            }

            return true
        }
    })

    override fun onTouch(p0: View?, p1: MotionEvent?): Boolean {
        gestureDetector.onTouchEvent(p1)
        return true
    }
})

它会按原样暂停和播放视频,我正在寻找的只是在视频暂停时显示暂停图标。谢谢。

要在 Exo Player 中播放和暂停,您将像这样使用它。

Exo Player 处理剩下的事情。

player.play(); //starts the playing process
player.pause(); //pauses the media.
player.setPlayWhenReady //this is not for play and pause functionality. It is designed for starting the playback when the resource is ready.

更新

使用以下播放器布局。

    <com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/feed_video_player"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:background="@android:color/black"
        app:controller_layout_id="@layout/custom_player_controller"
        app:resize_mode="fixed_width"
        app:show_timeout="5000"
        android:paddingBottom="55dp"
        android:background="#000"
        app:use_controller="true" />