Detect pause/resume in ExoPlayer

后端 未结 7 1937
予麋鹿
予麋鹿 2021-02-06 23:02

I searched two days for this question in github but i can\'t find true answer . I want example for detecting pause / resume in ExoPlayer > 2.x . An

7条回答
  •  走了就别回头了
    2021-02-06 23:56

    I had the same requirement to detect the click event of exoplayer play/pause button. Above answers were mainly talking about the state not about the button click event.

    This is what I did to detect the Play/Pause button click, works perfect.

    Step 1: Create custom control dispatcher class and override the method dispatchSetPlayWhenReady

    class PlayerControlDispatcher : DefaultControlDispatcher() {
        override fun dispatchSetPlayWhenReady(player: Player?, playWhenReady: Boolean): Boolean {
            if(playWhenReady) {
               // Play button clicked
            } else {
              // Paused button clicked
            }
            return super.dispatchSetPlayWhenReady(player, playWhenReady)
        }
    }
    

    Step 2: Set the custom control dispatcher class PlayerControlDispatcher into the the player view.

    playerView.setControlDispatcher(PlayerControlDispatcher())
    

    Where playerView is an instance of com.google.android.exoplayer2.ui.PlayerView which we declare in our layout file.

提交回复
热议问题