improved the code so that we can use the AudioPlayerState directly to check the playback speed and added localization

This commit is contained in:
Mauro Romito
2026-02-19 16:05:58 +01:00
committed by Mauro
parent 285f8b7834
commit 3dfcb6912f
13 changed files with 51 additions and 48 deletions
@@ -422,14 +422,14 @@ class TimelineInteractionHandler {
let availableSpeeds = VoiceMessagePlaybackSpeed.allCases
guard let currentIndex = availableSpeeds.firstIndex(of: appSettings.voiceMessagePlaybackSpeed) else {
appSettings.voiceMessagePlaybackSpeed = .default
audioPlayerState(for: itemID)?.setPlaybackSpeed(VoiceMessagePlaybackSpeed.default.rawValue)
audioPlayerState(for: itemID)?.setPlaybackSpeed(VoiceMessagePlaybackSpeed.default)
return
}
let nextIndex = (currentIndex + 1) % availableSpeeds.count
let nextSpeed = availableSpeeds[nextIndex]
appSettings.voiceMessagePlaybackSpeed = nextSpeed
audioPlayerState(for: itemID)?.setPlaybackSpeed(nextSpeed.rawValue)
audioPlayerState(for: itemID)?.setPlaybackSpeed(nextSpeed)
}
func playPauseAudio(for itemID: TimelineItemIdentifier) async {
@@ -461,7 +461,6 @@ class TimelineInteractionHandler {
// Ensure this one is attached
if !audioPlayerState.isAttached {
audioPlayerState.attachAudioPlayer(audioPlayer)
audioPlayerState.setPlaybackSpeed(appSettings.voiceMessagePlaybackSpeed.rawValue)
}
// Detach all other states
@@ -518,7 +517,9 @@ class TimelineInteractionHandler {
let playerState = AudioPlayerState(id: .timelineItemIdentifier(itemID),
title: L10n.commonVoiceMessage,
duration: voiceMessageRoomTimelineItem.content.duration,
waveform: voiceMessageRoomTimelineItem.content.waveform)
waveform: voiceMessageRoomTimelineItem.content.waveform,
playbackSpeed: appSettings.voiceMessagePlaybackSpeed,
playbackSpeedPublisher: appSettings.$voiceMessagePlaybackSpeed)
mediaPlayerProvider.register(audioPlayerState: playerState)
return playerState
}