Create VoicePlayerConfig.
This commit is contained in:
@@ -12,6 +12,7 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
@@ -38,9 +39,7 @@ class VoiceMessagePresenter(
|
||||
private val duration: Duration,
|
||||
) : Presenter<VoiceMessageState> {
|
||||
private val play = mutableStateOf<AsyncData<Unit>>(AsyncData.Uninitialized)
|
||||
private val playbackSpeed = mutableStateOf(1.0f)
|
||||
|
||||
private val availablePlaybackSpeeds = listOf(0.5f, 1.0f, 1.5f, 2.0f)
|
||||
private val playbackSpeedIndex = mutableIntStateOf(0)
|
||||
|
||||
@Composable
|
||||
override fun present(): VoiceMessageState {
|
||||
@@ -116,11 +115,8 @@ class VoiceMessagePresenter(
|
||||
player.seekTo((event.percentage * duration).toLong())
|
||||
}
|
||||
is VoiceMessageEvents.ChangePlaybackSpeed -> {
|
||||
val currentIndex = availablePlaybackSpeeds.indexOf(playbackSpeed.value)
|
||||
val nextIndex = (currentIndex + 1) % availablePlaybackSpeeds.size
|
||||
val newSpeed = availablePlaybackSpeeds[nextIndex]
|
||||
playbackSpeed.value = newSpeed
|
||||
player.setPlaybackSpeed(newSpeed)
|
||||
playbackSpeedIndex.intValue = (playbackSpeedIndex.intValue + 1) % VoicePlayerConfig.availablePlaybackSpeeds.size
|
||||
player.setPlaybackSpeed(VoicePlayerConfig.availablePlaybackSpeeds[playbackSpeedIndex.intValue])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,7 +126,7 @@ class VoiceMessagePresenter(
|
||||
progress = progress,
|
||||
time = time,
|
||||
showCursor = showCursor,
|
||||
playbackSpeed = playbackSpeed.value,
|
||||
playbackSpeed = VoicePlayerConfig.availablePlaybackSpeeds[playbackSpeedIndex.intValue],
|
||||
eventSink = ::handleEvent,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Element Creations Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.voiceplayer.impl
|
||||
|
||||
object VoicePlayerConfig {
|
||||
// Available playback speeds for voice messages, the first one is the default speed, and
|
||||
// the UI will allow to change to the next speed in the list, in loop.
|
||||
val availablePlaybackSpeeds = listOf(1.0f, 1.5f, 2.0f, 0.5f)
|
||||
}
|
||||
Reference in New Issue
Block a user