Android TV
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Android TV의 D패드 탐색
Android TV의 리모컨에는 Activity
의 dispatchKeyEvent(KeyEvent)
에 키 이벤트로 도착하는 명령어를 전송하는 D패드 컨트롤이 있습니다. 다음은 PlayerView
에 위임해야 합니다.
Kotlin
override fun dispatchKeyEvent(event: KeyEvent?): Boolean{
return playerView.dispatchKeyEvent(event!!) || super.dispatchKeyEvent(event)
}
자바
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
return playerView.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
}
PlayerView
의 포커스를 요청하는 것은 재생 컨트롤을 탐색하고 광고를 건너뛰는 데 중요합니다. Activity
의 onCreate
에서 포커스를 요청하는 것을 고려하세요.
Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
playerView.requestFocus()
// ...
}
자바
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ...
playerView.requestFocus();
// ...
}
Android TV에서 Compose를 사용하는 경우 AndroidView
에 포커스를 지정하고 수정자 매개변수를 AndroidView
에 전달하여 이벤트를 위임해야 합니다.
AndroidView(
modifier = modifier
.focusable()
.onKeyEvent { playerView.dispatchKeyEvent(it.nativeKeyEvent) },
factory = { playerView }
)
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-27(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"]]