我正在尝试将 EZAudio(https://github.com/syedhali/EZAudio)Objective-C 库转换为 Swift 3。我正在其中执行“EZAudioPlayFileExample”部分。
Objective-C
- (void)openFileWithFilePathURL:(NSURL*)filePathURL
{
self.audioFile = [EZAudioFile audioFileWithURL:filePathURL];
self.filePathLabel.text = filePathURL.lastPathComponent;
//
// Plot the whole waveform
//
self.audioPlot.plotType = EZPlotTypeBuffer;
self.audioPlot.shouldFill = YES;
self.audioPlot.shouldMirror = YES;
//
// Get the audio data from the audio file
//
__weak typeof (self) weakSelf = self;
[self.audioFile getWaveformDataWithCompletionBlock:^(float **waveformData,
int length)
{
[weakSelf.audioPlot updateBuffer:waveformData[0]
withBufferSize:length];
}];
}
斯威夫特 3
func openFileWithFilePathURL(filePathURL: NSURL) {
self.audioFile = EZAudioFile(url: filePathURL as URL!)
//
// Plot the whole waveform
//
self.plot.plotType = .buffer
self.plot.shouldFill = true
self.plot.shouldMirror = true
//
// Get the audio data from the audio file
//
weak var weakSelf = self
self.audioFile.getWaveformData(completionBlock: {(_ waveformData: Float, _ length: Int) -> Void in
weakSelf?.plot.updateBuffer(waveformData[0], withBufferSize: length) // error in this line as Float as no subscript members
})
}
我知道 Float 参数没有像 [0] 这样的下标成员。但我想转换 Objective-C 代码。或者这里的任何人都使用这个库的 Swift 版本。注意:我想要其中的“EZAudioPlayFileExample”。