首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVAudioRecorder不工作

AVAudioRecorder不工作
EN

Stack Overflow用户
提问于 2016-10-22 01:37:28
回答 1查看 499关注 0票数 0

无法获得AVAudioRecorder使用URL的代码。有人能在iOS和Swift 3上录制音频吗?下面的粗体文本显示了以下错误:

“不能使用类型的参数列表调用'AVAudioRecorder‘类型的初始化程序(URL: URL,设置.”

代码语言:javascript
复制
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    //Dispose of any resources that can be recreated.
}

func setupRecorder(){
    let recordSettings = [AVFormatIDKey : kAudioFormatAppleLossless,
                          AVEncoderAudioQualityKey : AVAudioQuality.max.rawValue,
                          AVEncoderBitRateKey : 320000,
                          AVNumberOfChannelsKey : 2,
                          AVSampleRateKey : 44100.0 ] as [String : Any]

    var error : NSError?

    func getCacheDirectory() -> String {
        let paths = NSSearchPathForDirectoriesInDomains(.cachesDirectory,.userDomainMask, true)

        return paths [0]
    }

    func getFileURL() -> URL {
        let path = (getCacheDirectory() as NSString).strings(byAppendingPaths: ["fileName"])
        let filePath = URL(fileURLWithPath: "path")
        return filePath
    }

    // Error on the following line
    soundRecorder = try AVAudioRecorder(url: getFileURL() as URL, settings: recordSettings, error: &error)


    if let err = error {
        NSLog("There was an error")
    }
    else {
        soundRecorder.delegate = self
        soundRecorder.prepareToRecord()
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-22 03:57:21

在Swift中,您不提供error参数,因为它是throws

改变这一点:

代码语言:javascript
复制
soundRecorder = try AVAudioRecorder(url: getFileURL() as URL, settings: recordSettings, error: &error)

至:

代码语言:javascript
复制
soundRecorder = try AVAudioRecorder(url: getFileURL() as URL, settings: recordSettings)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40187486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档