Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExoPlayer UI Controller Not Hiding with DPAD_DOWN in Media3 1.3.1 #2160

Open
shoval6 opened this issue Feb 18, 2025 · 1 comment
Open

ExoPlayer UI Controller Not Hiding with DPAD_DOWN in Media3 1.3.1 #2160

shoval6 opened this issue Feb 18, 2025 · 1 comment
Assignees
Labels

Comments

@shoval6
Copy link

shoval6 commented Feb 18, 2025

I am developing an Android TV application using ExoPlayer. In ExoPlayer 2.11.8, I used KEYCODE_DPAD_UP to show the player controls and KEYCODE_DPAD_DOWN to hide them. This functionality worked perfectly.

However, after migrating to Media3 1.3.1, the KEYCODE_DPAD_DOWN event does not hide the controls anymore. Instead, the UI remains visible, and the expected behavior does not occur.
Expected Behavior (as in ExoPlayer 2.11.8):

Pressing DPAD_UP → Shows the ExoPlayer controls.
Pressing DPAD_DOWN → Hides the ExoPlayer controls.

Observed Behavior in Media3 1.3.1:

Pressing DPAD_UP → Works correctly, the controls appear.
Pressing DPAD_DOWN → Controls do not hide, UI remains visible.

Code Implementation:

This is the code I used in ExoPlayer 2.11.8, which worked as expected:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
        binding.stPlayerView.showController();
    }
    if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        binding.stPlayerView.hideController();
    }
    return false;
}

After upgrading to Media3 1.3.1, the same code no longer hides the controller when pressing KEYCODE_DPAD_DOWN.

Current Dependencies:

// Old (Worked in ExoPlayer 2.11.8)
// implementation 'com.google.android.exoplayer:exoplayer:2.11.8'
// implementation 'com.google.android.exoplayer:exoplayer-ui:2.11.8'

// New (Issue in Media3 1.3.1)
implementation 'androidx.media3:media3-exoplayer:1.3.1'
implementation 'androidx.media3:media3-ui:1.3.1'

Questions :
Is there a new method or approach required in Media3 1.3.1 to hide the player controls with KEYCODE_DPAD_DOWN?
Has the behavior of hideController() changed in this version?
Are there any recommended workarounds to achieve the same functionality?

Thanks in advance for your help.

@icbaker
Copy link
Collaborator

icbaker commented Feb 19, 2025

At ExoPlayer 2.11.8, com.google.android.exoplayer2.ui.StyledPlayerView didn't exist - only com.google.android.exoplayer2.ui.PlayerView. So I assume this is the class you were using.

com.google.android.exoplayer2.ui.StyledPlayerView was renamed to androidx.media3.ui.PlayerView in the exoplayer2 -> media3 migration. com.google.android.exoplayer2.ui.PlayerView was not migrated. So in media3 you must be using androidx.media3.ui.PlayerView aka com.google.android.exoplayer2.ui.StyledPlayerView.

So it's likely you are observing a difference in behaviour between com.google.android.exoplayer2.ui.PlayerView and com.google.android.exoplayer2.ui.StyledPlayerView (rather than an exoplayer2 vs media3 difference).


This is the code I used in ExoPlayer 2.11.8, which worked as expected:

@OverRide
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
binding.stPlayerView.showController();
}
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
binding.stPlayerView.hideController();
}
return false;
}

Are either of these logic branches hit when you're using media3? I wonder if KEYCODE_DPAD_UP is being handled here (where any dpad key is interpreted to show the controller) rather than being passed to your app:

boolean isDpadKey = isDpadKey(event.getKeyCode());
boolean handled = false;
if (isDpadKey && useController() && !controller.isFullyVisible()) {
// Handle the key event by showing the controller.
maybeShowController(true);
handled = true;
} else if (dispatchMediaKeyEvent(event) || super.dispatchKeyEvent(event)) {
// The key event was handled as a media key or by the super class. We should also show the
// controller, or extend its show timeout if already visible.
maybeShowController(true);
handled = true;
} else if (isDpadKey && useController()) {
// The key event wasn't handled, but we should extend the controller's show timeout.
maybeShowController(true);
}

This would suggest it's not a problem with the implementation/functionality of the hideController method, but instead related to how the dpad events are routed/handled before they get to your app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants