mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
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:
@@ -31,6 +31,7 @@ struct AudioPlayerStateTests {
|
||||
audioPlayerMock.state = .stopped
|
||||
audioPlayerMock.currentTime = 0.0
|
||||
audioPlayerMock.duration = 0.0
|
||||
audioPlayerMock.playbackSpeed = 1.0
|
||||
audioPlayerMock.seekToClosure = { [audioPlayerSeekCallsSubject] progress in
|
||||
audioPlayerSeekCallsSubject?.send(progress)
|
||||
}
|
||||
@@ -274,6 +275,31 @@ struct AudioPlayerStateTests {
|
||||
#expect(!audioPlayerState.showProgressIndicator)
|
||||
}
|
||||
|
||||
func testSetPlaybackSpeed() {
|
||||
audioPlayerState.attachAudioPlayer(audioPlayerMock)
|
||||
|
||||
XCTAssertEqual(audioPlayerState.playbackSpeed, 1.0)
|
||||
|
||||
audioPlayerState.setPlaybackSpeed(1.5)
|
||||
XCTAssertEqual(audioPlayerState.playbackSpeed, 1.5)
|
||||
XCTAssertEqual(audioPlayerMock.setPlaybackSpeedReceivedSpeed, 1.5)
|
||||
|
||||
audioPlayerState.setPlaybackSpeed(2.0)
|
||||
XCTAssertEqual(audioPlayerState.playbackSpeed, 2.0)
|
||||
XCTAssertEqual(audioPlayerMock.setPlaybackSpeedReceivedSpeed, 2.0)
|
||||
|
||||
audioPlayerState.setPlaybackSpeed(0.5)
|
||||
XCTAssertEqual(audioPlayerState.playbackSpeed, 0.5)
|
||||
XCTAssertEqual(audioPlayerMock.setPlaybackSpeedReceivedSpeed, 0.5)
|
||||
}
|
||||
|
||||
func testSetPlaybackSpeedWithoutPlayer() {
|
||||
XCTAssertEqual(audioPlayerState.playbackSpeed, 1.0)
|
||||
|
||||
audioPlayerState.setPlaybackSpeed(2.0)
|
||||
XCTAssertEqual(audioPlayerState.playbackSpeed, 2.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
func audioPlayerActionsDidFailed() async throws {
|
||||
audioPlayerState.attachAudioPlayer(audioPlayerMock)
|
||||
|
||||
@@ -42,6 +42,7 @@ struct MediaPlayerProviderTests {
|
||||
func detachAllStates() {
|
||||
let audioPlayer = AudioPlayerMock()
|
||||
audioPlayer.actions = PassthroughSubject<AudioPlayerAction, Never>().eraseToAnyPublisher()
|
||||
audioPlayer.playbackSpeed = 1.0
|
||||
|
||||
let audioPlayerStates = Array(repeating: AudioPlayerState(id: .timelineItemIdentifier(.randomEvent), title: "", duration: 0), count: 10)
|
||||
for audioPlayerState in audioPlayerStates {
|
||||
@@ -62,6 +63,7 @@ struct MediaPlayerProviderTests {
|
||||
func detachAllStatesWithException() {
|
||||
let audioPlayer = AudioPlayerMock()
|
||||
audioPlayer.actions = PassthroughSubject<AudioPlayerAction, Never>().eraseToAnyPublisher()
|
||||
audioPlayer.playbackSpeed = 1.0
|
||||
|
||||
let audioPlayerStates = Array(repeating: AudioPlayerState(id: .timelineItemIdentifier(.randomEvent), title: "", duration: 0), count: 10)
|
||||
for audioPlayerState in audioPlayerStates {
|
||||
|
||||
@@ -42,6 +42,7 @@ class VoiceMessageRecorderTests: XCTestCase {
|
||||
audioPlayer = AudioPlayerMock()
|
||||
audioPlayer.actions = audioPlayerActions
|
||||
audioPlayer.state = .stopped
|
||||
audioPlayer.playbackSpeed = 1.0
|
||||
|
||||
mediaPlayerProvider = MediaPlayerProviderMock()
|
||||
mediaPlayerProvider.player = audioPlayer
|
||||
|
||||
Reference in New Issue
Block a user