使用 AudioKit 在 UIView 中绘制样本文件的波形

Using AudioKit to plot Waveform of samplefile in UIView

我正在 Swift 和 AudioKit 迈出第一步。我在操场上玩了一点。现在我正在尝试在 UIView 中绘制样本的波形。

我的代码无效。 UIView 保持空白。

@IBOutlet weak var audioOutputPlot: EZAudioPlot!

override func viewDidLoad() {
    super.viewDidLoad()

    let file = try! AKAudioFile(readFileName: "Sounds/drumloop_1.wav")
    let player = try! AKAudioPlayer(file: file)
    let plot = AKNodeOutputPlot(player, frame: audioOutputPlot.bounds)
    plot.plotType = .buffer
    plot.shouldFill = true
    plot.shouldMirror = true
    plot.color = UIColor.blue

    audioOutputPlot.addSubview(plot)

}

我已经将 @IBOutlet audioOutputPlot 与带有 Interface Builder 的 UIView 连接起来,并在它的自定义 Class 中写了 "EZAudioPlot"。

感谢您的帮助!

我认为您已经在 viewDidLoad 中本地声明了文件、播放器和绘图,但这些都被遗忘了。