mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Voice message waveform from audio files (#1919)
* Add DSWaveformImage * Add estimated waveform * Add progress mask modifier * Add real waveform * Fix cursor * Fix scale factor * Refine ProgressMaskModifier * Refine waveform logic * Add docs * Add waveform placeholder
This commit is contained in:
@@ -30,7 +30,7 @@ enum AudioPlayerPlaybackState {
|
||||
class AudioPlayerState: ObservableObject, Identifiable {
|
||||
let id = UUID()
|
||||
let duration: Double
|
||||
let waveform: Waveform
|
||||
let waveform: EstimatedWaveform
|
||||
@Published private(set) var playbackState: AudioPlayerPlaybackState
|
||||
@Published private(set) var progress: Double
|
||||
|
||||
@@ -38,6 +38,10 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
private var cancellables: Set<AnyCancellable> = []
|
||||
private var displayLink: CADisplayLink?
|
||||
|
||||
/// The file url that the last player attached to this object has loaded.
|
||||
/// The file url persists even if the AudioPlayer will be detached later.
|
||||
private(set) var fileURL: URL?
|
||||
|
||||
var isAttached: Bool {
|
||||
audioPlayer != nil
|
||||
}
|
||||
@@ -46,9 +50,9 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
displayLink != nil
|
||||
}
|
||||
|
||||
init(duration: Double, waveform: Waveform? = nil, progress: Double = 0.0) {
|
||||
init(duration: Double, waveform: EstimatedWaveform? = nil, progress: Double = 0.0) {
|
||||
self.duration = duration
|
||||
self.waveform = waveform ?? Waveform(data: [])
|
||||
self.waveform = waveform ?? EstimatedWaveform(data: [])
|
||||
self.progress = progress
|
||||
playbackState = .stopped
|
||||
}
|
||||
@@ -110,6 +114,7 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
playbackState = .loading
|
||||
case .didFinishLoading:
|
||||
playbackState = .readyToPlay
|
||||
fileURL = audioPlayer?.url
|
||||
case .didStartPlaying:
|
||||
if let audioPlayer {
|
||||
await restoreAudioPlayerState(audioPlayer: audioPlayer)
|
||||
|
||||
Reference in New Issue
Block a user