Skip to content

Commit

Permalink
fix: use default playback speed in playback ui
Browse files Browse the repository at this point in the history
i don't remember why i used 0 🤔
  • Loading branch information
abdallahmehiz committed Aug 21, 2024
1 parent fad046d commit ea4f754
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 37 deletions.
51 changes: 15 additions & 36 deletions app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Track>>(emptyList())
val subtitleTracks = _subtitleTracks.asStateFlow()
Expand Down

0 comments on commit ea4f754

Please sign in to comment.