Create VoicePlayerConfig.
This commit is contained in:
parent
8a52d2b8ce
commit
f59e979aab
2 changed files with 19 additions and 9 deletions
|
|
@ -12,6 +12,7 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.derivedStateOf
|
import androidx.compose.runtime.derivedStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import io.element.android.libraries.architecture.AsyncData
|
import io.element.android.libraries.architecture.AsyncData
|
||||||
|
|
@ -38,9 +39,7 @@ class VoiceMessagePresenter(
|
||||||
private val duration: Duration,
|
private val duration: Duration,
|
||||||
) : Presenter<VoiceMessageState> {
|
) : Presenter<VoiceMessageState> {
|
||||||
private val play = mutableStateOf<AsyncData<Unit>>(AsyncData.Uninitialized)
|
private val play = mutableStateOf<AsyncData<Unit>>(AsyncData.Uninitialized)
|
||||||
private val playbackSpeed = mutableStateOf(1.0f)
|
private val playbackSpeedIndex = mutableIntStateOf(0)
|
||||||
|
|
||||||
private val availablePlaybackSpeeds = listOf(0.5f, 1.0f, 1.5f, 2.0f)
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
override fun present(): VoiceMessageState {
|
override fun present(): VoiceMessageState {
|
||||||
|
|
@ -116,11 +115,8 @@ class VoiceMessagePresenter(
|
||||||
player.seekTo((event.percentage * duration).toLong())
|
player.seekTo((event.percentage * duration).toLong())
|
||||||
}
|
}
|
||||||
is VoiceMessageEvents.ChangePlaybackSpeed -> {
|
is VoiceMessageEvents.ChangePlaybackSpeed -> {
|
||||||
val currentIndex = availablePlaybackSpeeds.indexOf(playbackSpeed.value)
|
playbackSpeedIndex.intValue = (playbackSpeedIndex.intValue + 1) % VoicePlayerConfig.availablePlaybackSpeeds.size
|
||||||
val nextIndex = (currentIndex + 1) % availablePlaybackSpeeds.size
|
player.setPlaybackSpeed(VoicePlayerConfig.availablePlaybackSpeeds[playbackSpeedIndex.intValue])
|
||||||
val newSpeed = availablePlaybackSpeeds[nextIndex]
|
|
||||||
playbackSpeed.value = newSpeed
|
|
||||||
player.setPlaybackSpeed(newSpeed)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -130,7 +126,7 @@ class VoiceMessagePresenter(
|
||||||
progress = progress,
|
progress = progress,
|
||||||
time = time,
|
time = time,
|
||||||
showCursor = showCursor,
|
showCursor = showCursor,
|
||||||
playbackSpeed = playbackSpeed.value,
|
playbackSpeed = VoicePlayerConfig.availablePlaybackSpeeds[playbackSpeedIndex.intValue],
|
||||||
eventSink = ::handleEvent,
|
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)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue