Skip to content

Commit f83c59a

Browse files
committed
优化播放进度条
- tv 端不再使用波浪进度条 - 调低波浪高度 resolved #270
1 parent 876e214 commit f83c59a

File tree

3 files changed

+56
-6
lines changed
  • player
    • mobile/src/main/kotlin/dev/aaa1115910/bv/player/mobile
    • shared/src/main/kotlin/dev/aaa1115910/bv/player/seekbar
    • tv/src/main/kotlin/dev/aaa1115910/bv/player/tv

3 files changed

+56
-6
lines changed

player/mobile/src/main/kotlin/dev/aaa1115910/bv/player/mobile/SeekBar.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ import androidx.compose.ui.platform.LocalView
4141
import androidx.compose.ui.tooling.preview.Preview
4242
import androidx.compose.ui.unit.IntOffset
4343
import androidx.compose.ui.unit.dp
44-
import dev.aaa1115910.bv.player.seekbar.SeekBar
4544
import dev.aaa1115910.bv.player.seekbar.SeekBarThumb
4645
import dev.aaa1115910.bv.player.seekbar.SeekMoveState
46+
import dev.aaa1115910.bv.player.seekbar.WavySeekBar
4747
import dev.aaa1115910.bv.util.formatHourMinSec
4848
import kotlinx.coroutines.delay
4949
import kotlin.math.max
@@ -116,7 +116,7 @@ fun VideoSeekBar(
116116
contentAlignment = Alignment.Center
117117
) {
118118
sliderWidth = this.maxWidth
119-
SeekBar(
119+
WavySeekBar(
120120
modifier = Modifier.padding(horizontal = 16.dp),
121121
duration = duration,
122122
position = if (pressing) previewPosition else position,

player/shared/src/main/kotlin/dev/aaa1115910/bv/player/seekbar/SeekBar.kt

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import kotlin.math.max
3535
import kotlin.math.sin
3636

3737
@Composable
38-
fun SeekBar(
38+
fun WavySeekBar(
3939
modifier: Modifier = Modifier,
4040
duration: Long,
4141
position: Long,
@@ -73,7 +73,7 @@ fun SeekBar(
7373
}
7474

7575
val ampPx by animateFloatAsState(
76-
targetValue = if (waving) 8f else 0f,
76+
targetValue = if (waving) 6f else 0f,
7777
animationSpec = spring(
7878
dampingRatio = Spring.DampingRatioNoBouncy,
7979
stiffness = Spring.StiffnessVeryLow
@@ -180,6 +180,58 @@ fun SeekBar(
180180
}
181181
}
182182

183+
184+
@Composable
185+
fun SeekBar(
186+
modifier: Modifier = Modifier,
187+
duration: Long,
188+
position: Long,
189+
bufferedPercentage: Int,
190+
colors: SliderColors = SliderDefaults.colors(),
191+
) {
192+
val trackWidth = 10f
193+
Canvas(
194+
modifier = modifier
195+
.fillMaxWidth()
196+
.height(trackWidth.dp)
197+
) {
198+
drawLine(
199+
color = colors.inactiveTrackColor,
200+
start = Offset(0f, center.y),
201+
end = Offset(size.width - 0f, center.y),
202+
strokeWidth = trackWidth,
203+
cap = StrokeCap.Round
204+
)
205+
drawLine(
206+
color = colors.disabledActiveTrackColor,
207+
start = Offset(0f, center.y),
208+
end = Offset(size.width * bufferedPercentage / 100, center.y),
209+
strokeWidth = trackWidth,
210+
cap = StrokeCap.Round
211+
)
212+
drawLine(
213+
color = colors.activeTrackColor,
214+
start = Offset(0f, center.y),
215+
end = Offset(size.width * (position / duration.toFloat()), center.y),
216+
strokeWidth = trackWidth,
217+
cap = StrokeCap.Round
218+
)
219+
}
220+
}
221+
222+
@Preview
223+
@Composable
224+
private fun WavySeekPreview() {
225+
MaterialTheme {
226+
WavySeekBar(
227+
modifier = Modifier.padding(horizontal = 16.dp),
228+
duration = 1000,
229+
position = 300,
230+
bufferedPercentage = 50
231+
)
232+
}
233+
}
234+
183235
@Preview
184236
@Composable
185237
private fun SeekPreview() {

player/tv/src/main/kotlin/dev/aaa1115910/bv/player/tv/SeekBar.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ private fun VideoSeekBar(
8686
duration = duration,
8787
position = position,
8888
bufferedPercentage = bufferedPercentage,
89-
waving = playing,
90-
showThumb = useDefaultThumb,
9189
colors = colors
9290
)
9391
thumb?.invoke(

0 commit comments

Comments
 (0)