-
-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathProgressWaveformView.swift
More file actions
41 lines (35 loc) · 1.17 KB
/
ProgressWaveformView.swift
File metadata and controls
41 lines (35 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import DSWaveformImage
import DSWaveformImageViews
import SwiftUI
struct ProgressWaveformView: View {
let audioURL: URL
let progress: Double
var body: some View {
GeometryReader { geometry in
WaveformView(audioURL: audioURL) { shape in
shape.fill(.white)
shape.fill(.red).mask(alignment: .leading) {
Rectangle().frame(width: geometry.size.width * progress)
}
}
}
}
}
struct ProgressExampleView: View {
private let audioURL = Bundle.main.url(forResource: "example_sound", withExtension: "m4a")!
@State private var progress: Double = .random(in: 0...1)
var body: some View {
VStack {
ProgressWaveformView(audioURL: audioURL, progress: progress)
Button(action: { withAnimation { progress = .random(in: 0...1) }}) {
Label("Progress", systemImage: "dice.fill")
}.buttonStyle(.borderedProminent)
}
.background(Color(.systemYellow).ignoresSafeArea())
}
}
struct ProgressExampleView_Previews: PreviewProvider {
static var previews: some View {
ProgressExampleView()
}
}