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:
@@ -48,7 +48,8 @@ class AudioPlayer: NSObject, AudioPlayerProtocol {
|
||||
private let releaseAudioSessionTimeoutInterval = 5.0
|
||||
|
||||
private(set) var playbackURL: URL?
|
||||
|
||||
private(set) var playbackSpeed: Float = 1.0
|
||||
|
||||
private var deinitInProgress = false
|
||||
|
||||
var duration: TimeInterval {
|
||||
@@ -106,7 +107,7 @@ class AudioPlayer: NSObject, AudioPlayerProtocol {
|
||||
func play() {
|
||||
isStopped = false
|
||||
setupAudioSession()
|
||||
internalAudioPlayer?.play()
|
||||
internalAudioPlayer?.rate = playbackSpeed
|
||||
}
|
||||
|
||||
func pause() {
|
||||
@@ -128,7 +129,14 @@ class AudioPlayer: NSObject, AudioPlayerProtocol {
|
||||
let time = progress * duration
|
||||
await internalAudioPlayer.seek(to: CMTime(seconds: time, preferredTimescale: 60))
|
||||
}
|
||||
|
||||
|
||||
func setPlaybackSpeed(_ speed: Float) {
|
||||
playbackSpeed = speed
|
||||
if state == .playing {
|
||||
internalAudioPlayer?.rate = speed
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func setupAudioSession() {
|
||||
|
||||
@@ -40,15 +40,17 @@ protocol AudioPlayerProtocol: AnyObject {
|
||||
var currentTime: TimeInterval { get }
|
||||
var playbackURL: URL? { get }
|
||||
var state: MediaPlayerState { get }
|
||||
|
||||
var playbackSpeed: Float { get }
|
||||
|
||||
var actions: AnyPublisher<AudioPlayerAction, Never> { get }
|
||||
|
||||
|
||||
func load(sourceURL: URL, playbackURL: URL, autoplay: Bool)
|
||||
func reset()
|
||||
func play()
|
||||
func pause()
|
||||
func stop()
|
||||
func seek(to progress: Double) async
|
||||
func setPlaybackSpeed(_ speed: Float)
|
||||
}
|
||||
|
||||
// sourcery: AutoMockable
|
||||
|
||||
@@ -36,6 +36,7 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
/// It's similar to `playbackState`, with the a difference: `.loading`
|
||||
/// updates are delayed by a fixed amount of time
|
||||
@Published private(set) var playerButtonPlaybackState: AudioPlayerPlaybackState
|
||||
@Published private(set) var playbackSpeed: Float = 1.0
|
||||
|
||||
private weak var audioPlayer: AudioPlayerProtocol?
|
||||
private var audioPlayerSubscription: AnyCancellable?
|
||||
@@ -110,7 +111,12 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
func reportError() {
|
||||
playbackState = .error
|
||||
}
|
||||
|
||||
|
||||
func setPlaybackSpeed(_ speed: Float) {
|
||||
playbackSpeed = speed
|
||||
audioPlayer?.setPlaybackSpeed(speed)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func subscribeToAudioPlayer(audioPlayer: AudioPlayerProtocol) {
|
||||
|
||||
Reference in New Issue
Block a user