mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Fix: Keep the progress indicator visible after pausing or scrubbing a voice message. (#1969)
This commit is contained in:
@@ -38,6 +38,7 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
let waveform: EstimatedWaveform
|
||||
@Published private(set) var playbackState: AudioPlayerPlaybackState
|
||||
@Published private(set) var progress: Double
|
||||
@Published private(set) var showProgressIndicator: Bool
|
||||
|
||||
private weak var audioPlayer: AudioPlayerProtocol?
|
||||
private var cancellables: Set<AnyCancellable> = []
|
||||
@@ -60,6 +61,7 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
self.duration = duration
|
||||
self.waveform = waveform ?? EstimatedWaveform(data: [])
|
||||
self.progress = progress
|
||||
showProgressIndicator = false
|
||||
playbackState = .stopped
|
||||
}
|
||||
|
||||
@@ -71,8 +73,17 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
func updateState(progress: Double) async {
|
||||
let progress = max(0.0, min(progress, 1.0))
|
||||
self.progress = progress
|
||||
showProgressIndicator = true
|
||||
if let audioPlayer {
|
||||
var shouldResumeProgressPublishing = false
|
||||
if audioPlayer.state == .playing {
|
||||
shouldResumeProgressPublishing = true
|
||||
stopPublishProgress()
|
||||
}
|
||||
await audioPlayer.seek(to: progress)
|
||||
if shouldResumeProgressPublishing, audioPlayer.state == .playing {
|
||||
startPublishProgress()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,12 +97,12 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
}
|
||||
|
||||
func detachAudioPlayer() {
|
||||
guard audioPlayer != nil else { return }
|
||||
audioPlayer?.stop()
|
||||
stopPublishProgress()
|
||||
cancellables = []
|
||||
audioPlayer = nil
|
||||
playbackState = .stopped
|
||||
showProgressIndicator = false
|
||||
}
|
||||
|
||||
func reportError(_ error: Error) {
|
||||
@@ -127,14 +138,17 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
}
|
||||
startPublishProgress()
|
||||
playbackState = .playing
|
||||
showProgressIndicator = true
|
||||
case .didPausePlaying, .didStopPlaying, .didFinishPlaying:
|
||||
stopPublishProgress()
|
||||
playbackState = .stopped
|
||||
if case .didFinishPlaying = action {
|
||||
progress = 0.0
|
||||
showProgressIndicator = false
|
||||
}
|
||||
case .didFailWithError:
|
||||
stopPublishProgress()
|
||||
playbackState = .error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user