CookieMonsta
CookieMonsta

Reputation: 25

ExoPlayer is not showing play/pause during video playback

I am working on app that will play the videos using ExoPlayer. For some reason when I am trying to pause video player is not showing play/pause icons. I made a custom layout for only play/pause and set it on PlayerView. Playing/pause video with player.playWhenReady = true or player.playWhenReady = true. Can not find a solution anywhere, looks like I missing something but don't know what.

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>

I am using ExoPlayer inside RecyclerView, here is 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>

Then to play/pause video in RVAdapter I am doing this

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

It pauses and plays video as it should, all what I am looking for is just to display pause icon when video is paused. Thanks.

Upvotes: 1

Views: 3636

Answers (1)

Eyosiyas
Eyosiyas

Reputation: 1507

To play and pause in Exo Player you will use it like this.

Exo Player handles the rest.

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.

Update

Use the following player layout.

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

Upvotes: 1

Related Questions