我正在使用 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 不绘制吗?
感谢您的见解!!!