Voice message: variable play back speed (#5121)

* Implement voice message variable playback speed

* Move playback speed string to Untranslated

https://github.com/element-hq/element-x-ios/pull/5121#discussion_r2822631371

* Address review feedback for voice message playback speed

- Persist voice message playback speed as an enum in AppSettings instead of storing an index.
- Update playback speed cycling to derive from enum allCases and safely fall back to `.default` if the stored value cannot be resolved.
- Apply runtime speed updates in AudioPlayer only when the player is in the `.playing` state.
- Keep MediaPlayerProviderTests formatting/indentation style intact while retaining mock playback speed setup.
- Regenerate preview snapshots for:
  - PlaybackSpeedButton
  - VoiceMessageRoomPlaybackView
  - VoiceMessageRoomTimelineView

* Move VoiceMessagePlaybackSpeed outside AppSettings, remove speedRatio

* Stabilize PlaybackSpeedButton width

* Sync voice-message speed label

- Add voiceMessagePlaybackSpeed to TimelineViewState and bind it from appSettings.$voiceMessagePlaybackSpeed.
- Pass that timeline-level speed into VoiceMessageRoomPlaybackView and use it for PlaybackSpeedButton, so labels update consistently across items.
- Use @EnvironmentObject in VoiceMessageRoomTimelineContent so the view re-renders when timeline context state changes.
- In WaveformInteractionModifier, add .allowsHitTesting(showCursor) to the cursor interaction view so hidden pre-playback cursor hit area does not steal taps from the speed button.
This commit is contained in:
Florian
2026-02-19 14:02:26 +01:00
committed by Mauro
parent 7982aef855
commit 285f8b7834
33 changed files with 269 additions and 39 deletions
@@ -1222,6 +1222,11 @@ class AudioPlayerMock: AudioPlayerProtocol, @unchecked Sendable {
set(value) { underlyingState = value }
}
var underlyingState: MediaPlayerState!
var playbackSpeed: Float {
get { return underlyingPlaybackSpeed }
set(value) { underlyingPlaybackSpeed = value }
}
var underlyingPlaybackSpeed: Float!
var actions: AnyPublisher<AudioPlayerAction, Never> {
get { return underlyingActions }
set(value) { underlyingActions = value }
@@ -1450,6 +1455,47 @@ class AudioPlayerMock: AudioPlayerProtocol, @unchecked Sendable {
}
await seekToClosure?(progress)
}
//MARK: - setPlaybackSpeed
var setPlaybackSpeedUnderlyingCallsCount = 0
var setPlaybackSpeedCallsCount: Int {
get {
if Thread.isMainThread {
return setPlaybackSpeedUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = setPlaybackSpeedUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
setPlaybackSpeedUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
setPlaybackSpeedUnderlyingCallsCount = newValue
}
}
}
}
var setPlaybackSpeedCalled: Bool {
return setPlaybackSpeedCallsCount > 0
}
var setPlaybackSpeedReceivedSpeed: Float?
var setPlaybackSpeedReceivedInvocations: [Float] = []
var setPlaybackSpeedClosure: ((Float) -> Void)?
func setPlaybackSpeed(_ speed: Float) {
setPlaybackSpeedCallsCount += 1
setPlaybackSpeedReceivedSpeed = speed
DispatchQueue.main.async {
self.setPlaybackSpeedReceivedInvocations.append(speed)
}
setPlaybackSpeedClosure?(speed)
}
}
class AudioRecorderMock: AudioRecorderProtocol, @unchecked Sendable {
var actions: AnyPublisher<AudioRecorderAction, Never> {