Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
feat: add speed controls
Browse files Browse the repository at this point in the history
  • Loading branch information
kuylar committed Aug 30, 2023
1 parent 1e348bf commit 64a9875
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PlayerSettingsFragment(

loadQualityMenu()
loadSubtitleMenu()
loadSpeedMenu()
binding.playerSettingsLoopValue.text =
if (player.repeatMode == Player.REPEAT_MODE_ONE) getString(R.string.on)
else getString(R.string.off)
Expand Down Expand Up @@ -194,4 +195,28 @@ class PlayerSettingsFragment(
binding.playerSettingsButtonCaption.visibility = View.GONE
}
}

private fun loadSpeedMenu() {
val currentSpeed = player.playbackParameters.speed

binding.playerSettingsSpeedValue.text = formatSpeedString(currentSpeed)

floatArrayOf(0.25f, 0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f).forEach { speed ->
binding.playerSettingsSpeed.addView(createMenuItem(
formatSpeedString(speed),
currentSpeed == speed
) {
player.setPlaybackSpeed(speed)
dismissNow()
})
}
}

private fun formatSpeedString(speed: Float): String {
return when (speed) {
1f -> getString(R.string.player_speed_default)
2f -> getString(R.string.player_speed_template, "2")
else -> getString(R.string.player_speed_template, speed.toString())
}
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Your data is stored in the instance you chose (%s).</string>
<string name="player_track">Audio track</string>
<string name="player_quality_auto">Auto</string>
<string name="player_speed_default">Normal</string>
<string name="player_speed_template">%sx</string>

<!-- Update checker -->
<string name="update_title">New version available</string>
Expand Down

0 comments on commit 64a9875

Please sign in to comment.