ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Dpad issue -

Open NaveenMobileProgramming opened this issue 3 years ago • 4 comments

I have a Question. if I press any button from the tv remote, the controller is visible. I want to make the functionality like if the controller is not visible and the user clicks the KEYCODE_DPAD_UP then should change/next the channel or movie instead of showing the control.

On the other way, I want to handle all the Dpad events itself, so how to disable the dispatch event of StyledPlayerView ?

NaveenMobileProgramming avatar Aug 16 '22 11:08 NaveenMobileProgramming

At Activity override :

override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {

    when(keyCode) {
        KeyEvent.KEYCODE_DPAD_UP -> nextChannel()
        KeyEvent.KEYCODE_DPAD_DOWN -> previousChannel()
        KeyEvent.KEYCODE_DPAD_CENTER -> showHiddenController()
        KeyEvent.KEYCODE_0 -> setOptionChannel("0")
        KeyEvent.KEYCODE_1 -> setOptionChannel("1")
        KeyEvent.KEYCODE_2 -> setOptionChannel("2")
        KeyEvent.KEYCODE_3 -> setOptionChannel("3")
        KeyEvent.KEYCODE_4 -> setOptionChannel("4")
        KeyEvent.KEYCODE_5 -> setOptionChannel("5")
        KeyEvent.KEYCODE_6 -> setOptionChannel("6")
        KeyEvent.KEYCODE_7 -> setOptionChannel("7")
        KeyEvent.KEYCODE_8 -> setOptionChannel("8")
        KeyEvent.KEYCODE_9 -> setOptionChannel("9")
        KeyEvent.KEYCODE_DEL -> deleteOptionChannel()

    }
    return super.onKeyDown(keyCode, event);
}

You can do the following:

Set :

        playerView.player = exoPlayer
        playerView.controllerShowTimeoutMs = 10000
        playerView.useController = false
        playerView.controllerAutoShow = false
        
        playerView.setControllerVisibilityListener  { visibility ->
            if (visibility == View.VISIBLE) {
                /// Controller View.VISIBLE
            } else {
                //After 1000 ms the Controller is hidden, then put
                playerView.useController = false // do not use Controller  , button from the tv remote, the controller is no visible
            }
        }

Show Controller:

        playerView.useController = true
        playerView.showController()

DinhLap96 avatar Aug 16 '22 17:08 DinhLap96

The above solution is not working for me even i override the onKeyDown and onKeyUp methods in my player activity.

(When i tapped DPAD center first, the controls are shown and any further tap with send the event for the currently selected button) even i use
playerView.controllerAutoShow = false

is there any method to disable the auto controller shown when the user click the below events KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_DPAD_CENTER

I want that feature like the below code when (keyCode) { KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_DPAD_CENTER, -> { if (streamType == AppConstant.KEY_TYPE_LIVE) { if (!isControllerVisible()) { handleChanelMenu() true } else false } else { if (!isControllerVisible()) showController() true } } else -> false }

NaveenMobileProgramming avatar Sep 16 '22 05:09 NaveenMobileProgramming

This is what worked for me : 1- from the video activity: `

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch(keyCode)
    {
        case   KeyEvent.KEYCODE_DPAD_RIGHT:
        {
            Log.d(TAG,"KEYCODE_DPAD_RIGHT");
            try{
                if(player!=null && player.isPlaying())
                {
                    player.seekTo(player.getCurrentPosition() + 20000); // 10000 = 10 Seconds
                    //Log.d(TAG,"onPause(): "+player.isPlaying());
                }
            }catch (Exception e)
            {
              
            }

            return true;
        }
        case   KeyEvent.KEYCODE_DPAD_LEFT:
        {
            Log.d(TAG,"KEYCODE_DPAD_Left");
            try{
                if(player!=null && player.isPlaying())
                {
                    player.seekTo(player.getCurrentPosition() - 20000); // 10000 = 10 Seconds
                }
            }catch (Exception e)
            {
                
            }

            return true;
        }
    }

    return super.onKeyDown(keyCode, event);
}

`

Now when I click right button on the remote it forwards the video and if I click left button it rewinds the video but the controllers are still visible on the screen (play,pause,progressbar) which really doesn't matter to me as long as I can use right and left keys on the remote control to speed and rewind the video.

Fahad-alkamli avatar Jun 09 '23 01:06 Fahad-alkamli

Hello, I have the exact same problem. Is there any solution for this? Actually, the player does not consume d-pad events in ExoPlayer 2. This is an issue specific to ExoPlayer 3.

abdulkadirMete avatar Mar 14 '24 07:03 abdulkadirMete