无法修复我的playAudio函数 - 错误参数标签'(contentsOf:,error :)'与任何可用的重载都不匹配

时间:2018-04-24 13:21:16

标签: swift avplayer avaudioplayer

由于错误,我无法编写audioPlayer部分:参数标签'(contentsOfURL:,error :)'与任何可用的重载都不匹配

我已经尝试编写contentOf而不是URL或更改一些括号,但这里没有幸运。有人可以帮忙吗?

以下功能:

@IBAction func playAudio(sender: AnyObject) {

        if audioRecorder?.isRecording == false{
            stopButton.isEnabled = true
            recordButton.isEnabled = false

            let error : NSError?

            do {

                audioPlayer = try AVAudioPlayer(contentsOfURL: audioRecorder!.url, error: error)

            audioPlayer?.delegate = self as? AVAudioPlayerDelegate

            if let err = error{
                print("audioPlayer error: \(err.localizedDescription)")
            }else{
                audioPlayer?.play()
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

正确的AVAudioPlayer类init是:

def lnprior(theta):
    a, b, c = theta
    #flat priors on b, c
    if not 1.0 < b < 2.0 and 1.0 < c < 2.0:
        return -np.inf
    #gaussian prior on a
    mu = 10
    sigma = 1
    return np.log(1.0/(np.sqrt(2*np.pi)*sigma))-0.5*(a-mu)**2/sigma**2

检查如何实现do catch块,代码变为:

init(contentsOf: URL)