以编程方式创建的 EZAudioPlot 不绘制

Programmatically created EZAudioPlot does not draw

我正在使用 EZAudioPlayer 播放音频文件。 我想在 EZAudioPlot 上绘制声波。

我成功了。 但是,当我以编程方式创建 EZAudioPlot 时,视图显示但没有绘制声波。

这是部分代码

var audioPlayer: EZAudioPlayer!
@IBOutlet weak var plot1: EZAudioPlot!
var plot1Flag:Bool = true

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let plotType: EZPlotType = EZPlotType(rawValue: 1)!;
    plot1?.plotType = plotType
    plot1?.shouldFill = true;
    plot1?.shouldMirror = true;


    plot2 = EZAudioPlot()
    plot2.plotType = plotType
    plot2.shouldFill = true;
    plot2.shouldMirror = true;
    plot2.frame = CGRectMake(10, 200, 200, 200)
    plot2.backgroundColor = UIColor.blueColor()
    plot2.color = UIColor.whiteColor()
    self.view.addSubview(plot2)
}

@IBAction func playSound(sender: UIButton) {
    audioPlayer = EZAudioPlayer(URL: NSURL.fileURLWithPath(NSBundle.mainBundle().pathForResource("Alright", ofType: "wav")!), delegate: self)
    audioPlayer.play()
    plot1Flag = !plot1Flag
}

func audioPlayer(audioPlayer: EZAudioPlayer!, playedAudio buffer: UnsafeMutablePointer<UnsafeMutablePointer<Float>>, withBufferSize bufferSize: UInt32, withNumberOfChannels numberOfChannels: UInt32, inAudioFile audioFile: EZAudioFile!) {
    if(plot1Flag){
        print("plot1")
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            self.plot1?.updateBuffer(buffer[0], withBufferSize: bufferSize);
        })
    }else{
        print("plot2")
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            self.plot2.updateBuffer(buffer[0], withBufferSize: bufferSize);
        })
    }

}

能告诉我为什么手动创建的plot2画不出来吗?

感谢您的指点!!!

对于实时显示,您需要将此行添加到 plot2 var

plot2.shouldOptimizeForRealtimePlot = false;

希望对你有帮助:)

这是文档:

@property (nonatomic, assign) BOOL shouldOptimizeForRealtimePlot;

A BOOL that allows optimizing the audio plot’s drawing for real-time displays. Since the update function may be updating the plot’s data very quickly (over 60 frames per second) this property will throttle the drawing calls to be 60 frames per second (or whatever the screen rate is). Specifically, it disables implicit path change animations on the waveformLayer and sets up a display link to render 60 fps (audio updating the plot at 44.1 kHz causes it to re-render 86 fps - far greater than what is needed for a visual display).