-
-
Notifications
You must be signed in to change notification settings - Fork 130
Description
When trying to render a waveform in a macOS app, I'm getting errors that seem to be related to the window size. When the app first builds and launches from Xcode, the waveform renders correctly. As soon as I begin to resize the window however, the error occurs repeatedly and the waveform either takes a long time to re-render (5-10 seconds or more) or doesn't re-render at all. Sometimes the waveform re-renders at the correct size, but often it does not.
The initial error I get when building is:
AddInstanceForFactory: No factory registered for id <CFUUID 0x60000305e4e0> F8BB1C28-BAE8-11D6-9C31-00039315CD46
And then this error 3 times:
AudioQueueObject.cpp:3329 _Start: Error (-4) getting reporterIDs
When I resize the window width, I get the above error a bunch of times, 10-20 or more, before the waveform eventually re-renders.
Here's my code:
import DSWaveformImage
import DSWaveformImageViews
import SwiftUI
struct ProgressWaveformView: View {
let audioURL: URL
let progress: Double
let lineWidth = 3.0
var body: some View {
GeometryReader { geometry in
WaveformView(audioURL: audioURL, configuration: .init(style: .striped(.init(color: .black, width: lineWidth, spacing: lineWidth / 3)))) { shape in
shape.stroke(LinearGradient(colors: [.yellow, .green], startPoint: .top, endPoint: .bottom), lineWidth: lineWidth / 2).mask(alignment: .leading) {
Rectangle().frame(width: geometry.size.width)
}
shape.stroke(LinearGradient(colors: [.green, .yellow], startPoint: .top, endPoint: .bottom), lineWidth: lineWidth).mask(alignment: .leading) {
Rectangle().frame(width: geometry.size.width * progress)
}
}
}
}
}
struct ContentView: View {
private let audioURL = Bundle.main.url(forResource: "ExampleTrack", withExtension: "mp3")!
@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)
}
.padding()
}
}Here's what this looks like in the preview:

And when I build & run locally, initially it will look something like this:

Resizing the window larger looks like this for 10-30 seconds, sometimes never re-rendering:

When quitting and reopening or rerunning the app from Xcode, sometimes the waveform is the correct width, and sometimes it's still sized incorrectly.
Any idea what's going on here? My skills are quite junior in Swift/SwiftUI (long time UX designer learning to code here!) so fully prepared to accept that it's something dumb that I overlooked.