2

Hi I am trying to convert following Objective-C code to Swift:

EZAudioFile *audioFile = [EZAudioFile audioFileWithURL:NSURL]; //required type NSURL
[self.player playAudioFile:audioFile];

But I am unable to make it work.

let audioFile = EZAudioFile.url(EZAudioFile) //required type EZAudioFile, so I am unable to pass the NSURL of the audio file here.
player.play()

Error is : Cannot convert value of type 'NSURL' to expected argument type 'EZAudioFile'

The above objective-C code is referenced from here : EZAudio Example:Record File

4

1 回答 1

1

我没有测试,所以我可能是错的,但我认为你没有使用正确的语法:EZAudioFile.url(EZAudioFile)不调用你正在考虑的初始化程序。

在 EZAudioFile 源代码中看到确实有一个音频文件 URL 的初始化程序:

+ (instancetype)audioFileWithURL:(NSURL *)url

所以我的猜测是 Swift 中的语法应该是:

let audioFile = EZAudioFile(audioFileWithURL: yourURL)

此外,它似乎只是普通 URL init 的包装器,应该类似于:

let audioFile = EZAudioFile(URL: yourURL)
于 2016-03-31T12:28:50.277 回答