Skip to content

Commit 7fb4228

Browse files
committed
fix(player): Fix the problem where the initial values of speed control did not match
1 parent ca38531 commit 7fb4228

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/ui/component/player/SpeedControlFlyout.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fun SpeedControlFlyout(
9393
onHoverStateChanged: ((Boolean) -> Unit)? = null,
9494
onSpeedSelected: (SpeedItem) -> Unit = {}
9595
) {
96-
var selectedSpeed by remember { mutableStateOf(defaultSpeed) }
96+
var selectedSpeed by remember(defaultSpeed) { mutableStateOf(defaultSpeed) }
9797
var isExpanded by remember { mutableStateOf(false) }
9898
val coroutineScope = rememberCoroutineScope()
9999
var hideJob by remember { mutableStateOf<Job?>(null) }

composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/ui/screen/PlayerScreen.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import com.jankinwu.fntv.client.ui.component.player.NextEpisodePreviewFlyout
115115
import com.jankinwu.fntv.client.ui.component.player.PlayerSettingsMenu
116116
import com.jankinwu.fntv.client.ui.component.player.QualityControlFlyout
117117
import com.jankinwu.fntv.client.ui.component.player.SpeedControlFlyout
118+
import com.jankinwu.fntv.client.ui.component.player.speeds
118119
import com.jankinwu.fntv.client.ui.component.player.SubtitleControlFlyout
119120
import com.jankinwu.fntv.client.ui.component.player.SubtitleOverlay
120121
import com.jankinwu.fntv.client.data.model.SubtitleSettings
@@ -1512,7 +1513,18 @@ fun PlayerControlRow(
15121513
verticalAlignment = Alignment.CenterVertically
15131514
) {
15141515
// 倍速
1516+
val playbackSpeedFeature = remember(mediaPlayer) { mediaPlayer.features[PlaybackSpeed] }
1517+
1518+
// 直接访问 State 的 value 属性以触发重组
1519+
val speedStateValue = playbackSpeedFeature?.value
1520+
val currentSpeedValue = (speedStateValue as? Number)?.toFloat() ?: 1f
1521+
1522+
val currentSpeedItem = remember(currentSpeedValue) {
1523+
speeds.find { kotlin.math.abs(it.value - currentSpeedValue) < 0.01f } ?: speeds.find { it.value == 1.0f } ?: speeds[4]
1524+
}
1525+
15151526
SpeedControlFlyout(
1527+
defaultSpeed = currentSpeedItem,
15161528
yOffset = 70,
15171529
onHoverStateChanged = onSpeedControlHoverChanged,
15181530
onSpeedSelected = { item ->

0 commit comments

Comments
 (0)