Правка чата
This commit is contained in:
@@ -26,6 +26,10 @@ import kotlinx.coroutines.delay
|
||||
import androidx.compose.material.icons.filled.Download
|
||||
import androidx.compose.material.icons.filled.GraphicEq
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
|
||||
@Composable
|
||||
fun AppAudioPlayer(
|
||||
@@ -47,6 +51,7 @@ fun AppAudioPlayer(
|
||||
var currentPosition by remember { mutableLongStateOf(0L) }
|
||||
var duration by remember { mutableLongStateOf(0L) }
|
||||
var playbackSpeed by remember { mutableFloatStateOf(1.0f) }
|
||||
var layoutSize by remember { mutableStateOf(IntSize.Zero) }
|
||||
|
||||
val fileName = remember(url) { url.substringAfterLast("/") }
|
||||
|
||||
@@ -110,7 +115,7 @@ fun AppAudioPlayer(
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(36.dp)
|
||||
.size(40.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Color.White)
|
||||
.clickable { if (isPlaying) exoPlayer.pause() else exoPlayer.play() },
|
||||
@@ -119,8 +124,8 @@ fun AppAudioPlayer(
|
||||
Icon(
|
||||
imageVector = if (isPlaying) Icons.Default.Pause else Icons.Default.PlayArrow,
|
||||
contentDescription = null,
|
||||
tint = Color(0xFF3390EC),
|
||||
modifier = Modifier.size(24.dp)
|
||||
tint = Color(0xFF3096E5),
|
||||
modifier = Modifier.size(28.dp)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -129,68 +134,94 @@ fun AppAudioPlayer(
|
||||
.weight(1f)
|
||||
.padding(horizontal = 12.dp)
|
||||
) {
|
||||
Slider(
|
||||
value = if (duration > 0) currentPosition.toFloat() / duration.toFloat() else 0f,
|
||||
onValueChange = {
|
||||
val newPos = (it * duration).toLong()
|
||||
exoPlayer.seekTo(newPos)
|
||||
currentPosition = newPos
|
||||
},
|
||||
modifier = Modifier.height(16.dp),
|
||||
colors = SliderDefaults.colors(
|
||||
thumbColor = Color.White,
|
||||
activeTrackColor = Color.White,
|
||||
inactiveTrackColor = Color.White.copy(alpha = 0.3f)
|
||||
)
|
||||
)
|
||||
// Waveform / Progress
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(32.dp)
|
||||
.onSizeChanged { layoutSize = it }
|
||||
.pointerInput(duration) {
|
||||
detectTapGestures { offset ->
|
||||
if (duration > 0 && layoutSize.width > 0) {
|
||||
val pct = offset.x / layoutSize.width.toFloat()
|
||||
val newPos = (pct * duration).toLong()
|
||||
exoPlayer.seekTo(newPos)
|
||||
currentPosition = newPos
|
||||
}
|
||||
}
|
||||
},
|
||||
contentAlignment = Alignment.CenterStart
|
||||
) {
|
||||
androidx.compose.foundation.Canvas(modifier = Modifier.fillMaxSize()) {
|
||||
val barCount = 35
|
||||
val barSpacing = 2.dp.toPx()
|
||||
val barWidth = (size.width - (barCount - 1) * barSpacing) / barCount
|
||||
val progress = if (duration > 0) currentPosition.toFloat() / duration.toFloat() else 0f
|
||||
|
||||
// Fake consistent waveform items
|
||||
val barHeights = listOf(
|
||||
0.4f, 0.6f, 0.3f, 0.8f, 0.5f, 0.9f, 0.4f, 0.7f, 0.5f, 0.8f,
|
||||
0.3f, 0.7f, 0.6f, 0.9f, 0.4f, 0.8f, 0.5f, 0.7f, 0.3f, 0.9f,
|
||||
0.5f, 0.6f, 0.4f, 0.8f, 0.6f, 0.7f, 0.5f, 0.4f, 0.5f, 0.7f,
|
||||
0.4f, 0.3f, 0.5f, 0.6f, 0.4f
|
||||
)
|
||||
|
||||
for (i in 0 until barCount) {
|
||||
val x = i * (barWidth + barSpacing)
|
||||
val heightPct = barHeights[i % barHeights.size]
|
||||
val barHeight = size.height * heightPct
|
||||
val isActive = (i.toFloat() / barCount) <= progress
|
||||
|
||||
drawRoundRect(
|
||||
color = if (isActive) Color.White else Color.White.copy(alpha = 0.25f),
|
||||
topLeft = androidx.compose.ui.geometry.Offset(x, (size.height - barHeight) / 2),
|
||||
size = androidx.compose.ui.geometry.Size(barWidth, barHeight),
|
||||
cornerRadius = androidx.compose.ui.geometry.CornerRadius(2.dp.toPx())
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = formatDuration(currentPosition),
|
||||
fontSize = 10.sp,
|
||||
text = "${formatDuration(currentPosition)} / ${formatDuration(duration)}",
|
||||
fontSize = 11.sp,
|
||||
color = contentColor.copy(alpha = 0.7f)
|
||||
)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = "3.3 MB", // Mock size
|
||||
fontSize = 10.sp,
|
||||
color = contentColor.copy(alpha = 0.7f)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
if (!isVoiceMessage) {
|
||||
Icon(
|
||||
Icons.Default.Download,
|
||||
contentDescription = null,
|
||||
tint = contentColor.copy(alpha = 0.7f),
|
||||
modifier = Modifier.size(12.dp)
|
||||
modifier = Modifier.size(14.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isVoiceMessage) {
|
||||
Surface(
|
||||
onClick = {
|
||||
playbackSpeed = when (playbackSpeed) {
|
||||
1.0f -> 1.5f
|
||||
1.5f -> 2.0f
|
||||
else -> 1.0f
|
||||
}
|
||||
exoPlayer.playbackParameters = PlaybackParameters(playbackSpeed)
|
||||
},
|
||||
color = Color.White.copy(alpha = 0.2f),
|
||||
shape = CircleShape,
|
||||
modifier = Modifier.size(32.dp)
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Text(
|
||||
text = "${if (playbackSpeed % 1.0f == 0.0f) playbackSpeed.toInt() else playbackSpeed}x",
|
||||
fontSize = 10.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.White
|
||||
)
|
||||
Surface(
|
||||
onClick = {
|
||||
playbackSpeed = when (playbackSpeed) {
|
||||
1.0f -> 1.5f
|
||||
1.5f -> 2.0f
|
||||
else -> 1.0f
|
||||
}
|
||||
exoPlayer.playbackParameters = PlaybackParameters(playbackSpeed)
|
||||
},
|
||||
color = Color.White.copy(alpha = 0.15f),
|
||||
shape = CircleShape,
|
||||
modifier = Modifier.size(36.dp)
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Text(
|
||||
text = "${if (playbackSpeed % 1.0f == 0.0f) playbackSpeed.toInt() else playbackSpeed}x",
|
||||
fontSize = 11.sp,
|
||||
fontWeight = FontWeight.Black,
|
||||
color = Color.White
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user