From 631f2e3e27fb5285d280f43d3cfae77be4daf121 Mon Sep 17 00:00:00 2001 From: Koen Date: Fri, 18 Aug 2023 10:59:16 +0200 Subject: [PATCH] Fixed controls not being accessible due to DPAD handling. --- .../fcast/receiver/CustomStyledPlayerView.kt | 8 ++++++ .../com/futo/fcast/receiver/PlayerActivity.kt | 28 +++++++++---------- .../src/main/res/layout/activity_player.xml | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 receivers/android/app/src/main/java/com/futo/fcast/receiver/CustomStyledPlayerView.kt diff --git a/receivers/android/app/src/main/java/com/futo/fcast/receiver/CustomStyledPlayerView.kt b/receivers/android/app/src/main/java/com/futo/fcast/receiver/CustomStyledPlayerView.kt new file mode 100644 index 0000000..06e9f61 --- /dev/null +++ b/receivers/android/app/src/main/java/com/futo/fcast/receiver/CustomStyledPlayerView.kt @@ -0,0 +1,8 @@ +package com.futo.fcast.receiver + +import android.content.Context +import android.util.AttributeSet +import android.view.KeyEvent +import com.google.android.exoplayer2.ui.StyledPlayerView + +class CustomStyledPlayerView(context: Context, attrs: AttributeSet? = null) : StyledPlayerView(context, attrs) { } \ No newline at end of file diff --git a/receivers/android/app/src/main/java/com/futo/fcast/receiver/PlayerActivity.kt b/receivers/android/app/src/main/java/com/futo/fcast/receiver/PlayerActivity.kt index 43811a9..14310cc 100644 --- a/receivers/android/app/src/main/java/com/futo/fcast/receiver/PlayerActivity.kt +++ b/receivers/android/app/src/main/java/com/futo/fcast/receiver/PlayerActivity.kt @@ -245,26 +245,26 @@ class PlayerActivity : AppCompatActivity() { TcpListenerService.activityCount-- } - override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { - when (keyCode) { - KeyEvent.KEYCODE_DPAD_LEFT -> { - val newPosition = _exoPlayer.currentPosition - 10000 - _exoPlayer.seekTo(max(0, newPosition)) + override fun dispatchKeyEvent(event: KeyEvent): Boolean { + if (_playerControlView.isControllerFullyVisible) { + if (event.keyCode == KeyEvent.KEYCODE_BACK) { + _playerControlView.hideController() return true } - KeyEvent.KEYCODE_DPAD_RIGHT -> { - val newPosition = _exoPlayer.currentPosition + 10000 - _exoPlayer.seekTo(newPosition) - return true - } - KeyEvent.KEYCODE_BACK -> { - if (_playerControlView.isControllerFullyVisible) { - _playerControlView.hideController() + } else { + when (event.keyCode) { + KeyEvent.KEYCODE_DPAD_LEFT -> { + _exoPlayer.seekTo(max(0, _exoPlayer.currentPosition - SEEK_BACKWARD_MILLIS)) + return true + } + KeyEvent.KEYCODE_DPAD_RIGHT -> { + _exoPlayer.seekTo(_exoPlayer.currentPosition + SEEK_FORWARD_MILLIS) return true } } } - return super.onKeyDown(keyCode, event) + + return super.dispatchKeyEvent(event) } fun play(playMessage: PlayMessage) { diff --git a/receivers/android/app/src/main/res/layout/activity_player.xml b/receivers/android/app/src/main/res/layout/activity_player.xml index 4001e51..5c7b06e 100644 --- a/receivers/android/app/src/main/res/layout/activity_player.xml +++ b/receivers/android/app/src/main/res/layout/activity_player.xml @@ -6,7 +6,7 @@ xmlns:tools="http://schemas.android.com/tools" android:background="@color/black"> -