Android TV
Stay organized with collections
Save and categorize content based on your preferences.
D-pad navigation on Android TV
The remote control of Android TV has a D-pad control that sends commands that
arrive as key events at dispatchKeyEvent(KeyEvent)
of your Activity
. These
need to be delegated to the PlayerView
:
Kotlin
override fun dispatchKeyEvent(event: KeyEvent?): Boolean{
return playerView.dispatchKeyEvent(event!!) || super.dispatchKeyEvent(event)
}
Java
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
return playerView.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
}
Requesting focus for the PlayerView
is important for navigating playback
controls and skipping ads. Consider requesting the focus in onCreate
of the
Activity
:
Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
playerView.requestFocus()
// ...
}
Java
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ...
playerView.requestFocus();
// ...
}
If you are using Compose on Android TV, you need to make the AndroidView
focusable and delegate the event by passing the modifier parameter into the
AndroidView
accordingly:
AndroidView(
modifier = modifier
.focusable()
.onKeyEvent { playerView.dispatchKeyEvent(it.nativeKeyEvent) },
factory = { playerView }
)
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 UTC."],[],[],null,["D-pad navigation on Android TV\n\nThe remote control of Android TV has a D-pad control that sends commands that\narrive as key events at `dispatchKeyEvent(KeyEvent)` of your `Activity`. These\nneed to be delegated to the [`PlayerView`](/reference/androidx/media3/ui/PlayerView): \n\nKotlin \n\n```kotlin\noverride fun dispatchKeyEvent(event: KeyEvent?): Boolean{\n return playerView.dispatchKeyEvent(event!!) || super.dispatchKeyEvent(event)\n}\n```\n\nJava \n\n```java\n@Override\npublic boolean dispatchKeyEvent(KeyEvent event) {\n return playerView.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);\n}\n```\n\n\u003cbr /\u003e\n\nRequesting focus for the `PlayerView` is important for navigating playback\ncontrols and skipping ads. Consider requesting the focus in `onCreate` of the\n`Activity`: \n\nKotlin \n\n```kotlin\noverride fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n // ...\n playerView.requestFocus()\n // ...\n}\n```\n\nJava \n\n```java\n@Override\npublic void onCreate(@Nullable Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n // ...\n playerView.requestFocus();\n // ...\n}\n```\n\n\u003cbr /\u003e\n\nIf you are using Compose on Android TV, you need to make the [`AndroidView`](/reference/kotlin/androidx/compose/ui/viewinterop/package-summary#AndroidView(kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Function1))\nfocusable and delegate the event by passing the modifier parameter into the\n`AndroidView` accordingly: \n\n AndroidView(\n modifier = modifier\n .focusable()\n .onKeyEvent { playerView.dispatchKeyEvent(it.nativeKeyEvent) },\n factory = { playerView }\n )\n\n\u003cbr /\u003e"]]