Skip to content

Commit

Permalink
feat(player): video speed
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallahmehiz committed Jun 20, 2024
1 parent 6c1995f commit 27deffb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ class PlayerPreferences(
val videoAspect = preferenceStore.getEnum("video_aspect", VideoAspect.Fit)
val currentChaptersIndicator = preferenceStore.getBoolean("show_video_chapter_indicator", true)
val showChaptersButton = preferenceStore.getBoolean("show_video_chapters_button", false)

val defaultSpeed = preferenceStore.getFloat("default_speed", 1f)
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class PlayerActivity : AppCompatActivity() {
Debanding.GPU -> MPVLib.setPropertyString("deband", "yes")
}
if (decoderPreferences.useYUV420P.get()) MPVLib.setPropertyString("vf", "format=yuv420p")
MPVLib.setPropertyDouble("speed", playerPreferences.defaultSpeed.get().toDouble())

player.addObserver(PlayerObserver(this))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import `is`.xyz.mpv.MPVLib
import kotlinx.coroutines.flow.update
import live.mehiz.mpvkt.R
import live.mehiz.mpvkt.preferences.PlayerPreferences
import live.mehiz.mpvkt.preferences.preference.collectAsState
import live.mehiz.mpvkt.ui.player.PlayerViewModel
import live.mehiz.mpvkt.ui.player.Sheets
import live.mehiz.mpvkt.ui.player.controls.components.ControlsButton
Expand All @@ -32,6 +36,15 @@ fun BottomLeftPlayerControls(viewModel: PlayerViewModel) {
Icons.Default.Lock,
onClick = { viewModel.lockControls() },
)
val defaultSpeed by playerPreferences.defaultSpeed.collectAsState()
ControlsButton(
text = stringResource(R.string.player_speed, defaultSpeed),
onClick = {
val newSpeed = if (defaultSpeed >= 2) 0.25f else defaultSpeed + 0.25f
MPVLib.setPropertyDouble("speed", newSpeed.toDouble())
playerPreferences.defaultSpeed.set(newSpeed)
}
)
AnimatedVisibility(
currentChapter != null && playerPreferences.currentChaptersIndicator.get(),
enter = fadeIn(),
Expand Down
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 @@ -63,4 +63,5 @@
<string name="player_sheets_stats_page_title">Default statistics page</string>
<string name="player_sheets_stats_page_chip">Page %d</string>
<string name="player_seek_n_seconds">%d seconds</string>
<string name="player_speed">x%.2f</string>
</resources>

0 comments on commit 27deffb

Please sign in to comment.