我正在尝试将EZAudio(https://github.com/syedhali/EZAudio)Objective-C库转换为Swift 3.我正在进行" EZAudioPlayFileExample"参与其中。
- (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];
}];
}
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"在它。
答案 0 :(得分:0)
float **waveformData
实际上是unsafemutablepointer
。所以你必须在swift 3.0中使用unsafemutablepointer
。
您可以在swift中使用unsafemutablepointer,如
UnsafeMutablePointer<UnsafeMutablePointer<Float>>
您可以使用
self.audioFile.getWaveformData(completionBlock: {(_ waveformData: UnsafeMutablePointer<UnsafeMutablePointer<Float>>, _ length: Int) -> Void in
weakSelf?.plot.updateBuffer(waveformData[0], withBufferSize: length)
})
我刚刚下载了旧版本的EZAudio swift实现并转换为swift 3.0。它可以在link上找到 我不知道这会对你有什么帮助,但你可以在此基础上建立。 您还可以参考gitHub页面上报告的此issue