I am playing audio file using EZAudioPlayer. I want the soundwave to be drawn on EZAudioPlot.
I succeeded in doing this. However, when I create EZAudioPlot programmatically, the view shows but no soundwave is drawn.
Here is some of the code
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);
})
}
}
Can you tell me why the manually created plot2 doesn't draw?
Thank you for your insight!!!
for real time displays you need to add this line to your plot2 var
Hope it helps you :)
Here is the documentation: