From ea4f7540f04d668975e79daacaa2d0f2af3658cb Mon Sep 17 00:00:00 2001 From: AbdallahMehiz Date: Wed, 21 Aug 2024 06:44:23 +0100 Subject: [PATCH] fix: use default playback speed in playback ui i don't remember why i used 0 :thinking: --- .../mehiz/mpvkt/ui/player/PlayerActivity.kt | 51 ++++++------------- .../mehiz/mpvkt/ui/player/PlayerViewModel.kt | 2 +- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt index 71e3ec4..f448386 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt @@ -155,10 +155,7 @@ class PlayerActivity : AppCompatActivity() { @SuppressLint("NewApi") override fun onUserLeaveHint() { - if (isPipSupported && - player.paused == false && - playerPreferences.automaticallyEnterPip.get() - ) { + if (isPipSupported && player.paused == false && playerPreferences.automaticallyEnterPip.get()) { enterPictureInPictureMode() } else { endPlayback(EndPlaybackReason.ExternalAction) @@ -334,13 +331,8 @@ class PlayerActivity : AppCompatActivity() { private fun parsePathFromIntent(intent: Intent): String? { intent.getStringArrayExtra("headers")?.let { headers -> if (headers[0].startsWith("User-Agent", true)) MPVLib.setPropertyString("user-agent", headers[1]) - val headersString = headers - .asSequence() - .drop(2) - .chunked(2) - .associate { it[0] to it[1] } - .map { "${it.key}: ${it.value.replace(",", "\\,")}" } - .joinToString(",") + val headersString = headers.asSequence().drop(2).chunked(2).associate { it[0] to it[1] } + .map { "${it.key}: ${it.value.replace(",", "\\,")}" }.joinToString(",") MPVLib.setPropertyString("http-header-fields", headersString) } return when (intent.action) { @@ -428,6 +420,7 @@ class PlayerActivity : AppCompatActivity() { viewModel.pause() window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) } else { + viewModel.unpause() window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) } } @@ -525,12 +518,7 @@ class PlayerActivity : AppCompatActivity() { private fun endPlayback(reason: EndPlaybackReason, cause: String? = null) { Log.d(TAG, "Ending playback") - CoroutineScope(Dispatchers.IO).launch { - saveVideoPlaybackState() - } - if (!intent.getBooleanExtra("return_result", false)) { - return - } + CoroutineScope(Dispatchers.IO).launch { saveVideoPlaybackState() } val returnIntent = Intent() returnIntent.putExtra("end_by", reason.value) cause?.let { returnIntent.putExtra("cause", cause) } @@ -635,25 +623,16 @@ class PlayerActivity : AppCompatActivity() { override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { when (keyCode) { - KeyEvent.KEYCODE_VOLUME_UP -> { - viewModel.changeVolumeBy(1) - } - - KeyEvent.KEYCODE_VOLUME_DOWN -> { - viewModel.changeVolumeBy(-1) - } - - KeyEvent.KEYCODE_DPAD_RIGHT -> { - viewModel.seekBy(playerPreferences.doubleTapToSeekDuration.get()) - } - - KeyEvent.KEYCODE_DPAD_LEFT -> { - viewModel.seekBy(-playerPreferences.doubleTapToSeekDuration.get()) - } - - KeyEvent.KEYCODE_SPACE -> { - viewModel.pauseUnpause() - } + KeyEvent.KEYCODE_VOLUME_UP -> viewModel.changeVolumeBy(1) + KeyEvent.KEYCODE_VOLUME_DOWN -> viewModel.changeVolumeBy(-1) + KeyEvent.KEYCODE_DPAD_RIGHT -> viewModel.seekBy(playerPreferences.doubleTapToSeekDuration.get()) + KeyEvent.KEYCODE_DPAD_LEFT -> viewModel.seekBy(-playerPreferences.doubleTapToSeekDuration.get()) + KeyEvent.KEYCODE_SPACE -> viewModel.pauseUnpause() + KeyEvent.KEYCODE_MEDIA_STOP -> endPlayback(EndPlaybackReason.ExternalAction) + + // They don't have a seek animation cause that's in GestureHandler.kt :despair: + KeyEvent.KEYCODE_MEDIA_REWIND -> viewModel.seekBy(-playerPreferences.doubleTapToSeekDuration.get()) + KeyEvent.KEYCODE_MEDIA_FAST_FORWARD -> viewModel.seekBy(playerPreferences.doubleTapToSeekDuration.get()) // other keys should be bound by the user in input.conf ig else -> { diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt index f10e609..a1388ac 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt @@ -30,7 +30,7 @@ class PlayerViewModel( val mediaTitle = MutableStateFlow("") val isLoading = MutableStateFlow(true) - val playbackSpeed = MutableStateFlow(0f) + val playbackSpeed = MutableStateFlow(playerPreferences.defaultSpeed.get()) private val _subtitleTracks = MutableStateFlow>(emptyList()) val subtitleTracks = _subtitleTracks.asStateFlow()