我在NSURL中遇到错误

时间:2017-12-01 09:20:07

标签: swift swift3

这是我的代码......

@IBAction func recordAction(_ sender: Any) {

 if  self.audioRecorder.isRecording {

   self.audioRecorder.stop()

  self.rcdBtn.setTitle("Record", for: UIControlState.normal)

    }else {
        let session = AVAudioSession.sharedInstance()

        do{

    try session.setActive(true)

    }catch{
            print("error to recording")
        }
        audioRecorder.record()
        rcdBtn.setTitle("Finish Recording", for: UIControlState.normal)

    }
}





 required init?(coder aDecoder: NSCoder) {

    let baseString: String = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]

    let pathComponents = [baseString,"MyAudio.mp3"]

   self.audioUrl = NSURL.fileURL(withPathComponents: pathComponents)! as NSURL

    let session = AVAudioSession.sharedInstance()


    do{
            try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
    }catch{
            print("Error")
    }


    var recordSettings: [String :Any] = Dictionary()
    recordSettings[AVFormatIDKey] = kAudioFormatMPEG4AAC
    recordSettings[AVSampleRateKey] = 44100.0
    recordSettings[AVNumberOfChannelsKey] = 2

    do{
      self.audioRecorder = try AVAudioRecorder(url: self.audioUrl as! URL, settings: recordSettings)
    }catch{
        print("Error at setting ")
    }
    //Super init is below
    super.init(coder: aDecoder)
}

我正在使用AVFoundation框架进行简单的录音项目......

这个错误我得到了.......

- [NSURL init]调用;这会导致NSURL实例具有空URL字符串。请使用其中一个记录的NSURL初始化方法(initWithString:,initFileURLWithPath:

0 个答案:

没有答案