gpt4 book ai didi

swift ,AVAudioRecorder : Error 317: ca_debug_string: inPropertyData == NULL

转载 作者:搜寻专家 更新时间:2023-10-30 22:17:07 24 4
gpt4 key购买 nike

我知道有些线程会出现此错误消息,但它们并没有真正提供问题的答案,这就是为什么我决定打开另一个线程并再次询问的原因...希望其他人遇到过同样的问题, 解决它。

import UIKit
import AVFoundation

class RecordSoundsViewController: UIViewController, AVAudioRecorderDelegate {

// MARK: IBOutlets for Buttons
@IBOutlet weak var recordingLable: UILabel!
@IBOutlet weak var recordButton: UIButton!
@IBOutlet weak var stopRecordingButton: UIButton!

var audioRecorder : AVAudioRecorder!

override func viewDidLoad() {
super.viewDidLoad()
stopRecordingButton.isEnabled = false
// Do any additional setup after loading the view, typically from a nib.
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}

@IBAction func recordAudio(_ sender: Any) {
configureUI(true) // Call to set Buttons enabled state correct

// MARK: AVAudio code and config....
let dirPath = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask, true)[0] as String
let recordingName = "recordedVoice.wav"
let pathArray = [dirPath, recordingName]
let filePath = URL(string: pathArray.joined(separator: "/"))

let session = AVAudioSession.sharedInstance()
try! session.setCategory(AVAudioSessionCategoryPlayAndRecord, with:AVAudioSessionCategoryOptions.defaultToSpeaker)

try! audioRecorder = AVAudioRecorder(url: filePath!, settings: [:])
audioRecorder.delegate = self
audioRecorder.isMeteringEnabled = true
audioRecorder.prepareToRecord()
audioRecorder.record() //ca_debug_string Error occurs when this call is made.
}

// MARK: IBAction Stop Recording
@IBAction func stopRecording(_ sender: Any) {
configureUI(false) // Call to set Buttons enabled state correct

audioRecorder.stop()
let audioSession = AVAudioSession.sharedInstance()
try! audioSession.setActive(false)
}

// MARK: Func audioRecorderDidFinishRecording
func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool) {
if flag {
performSegue(withIdentifier: "stopRecording", sender: audioRecorder.url)
} else {
print("recording was not successful")
}
}

// MARK: ConfigureUI Method for State of Buttons
func configureUI(_ recordingState: Bool) {
if recordingState {
recordingLable.text = "Recording in progress"
stopRecordingButton.isEnabled = true
recordButton.isEnabled = false
} else {
recordingLable.text = "Tap to record"
stopRecordingButton.isEnabled = false
recordButton.isEnabled = true
}
}

// MARK: Prepare Viewcontroller
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "stopRecording" {
let playSoundsVC = segue.destination as! PlaySoundsViewController //forced upcase
let recordedAudioURL = sender as! URL
playSoundsVC.recordedAudioURL = recordedAudioURL
}
}

}

发生错误的行:

audioRecorder.record()

程序不会中止或崩溃(在模拟器中)。录制工作正常,只是在调试器中弹出此消息。

如果有人知道可能导致问题的原因,请在此处分享,我们将不胜感激。非常感谢!

最佳答案

您的 session.setCategory 已过时,必须重命名:

不正确:

try! session.setCategory(AVAudioSessionCategoryPlayAndRecord, with:AVAudioSessionCategoryOptions.defaultToSpeaker)

正确:

try! session.setCategory(AVAudioSession.Category.playAndRecord, mode: AVAudioSession.Mode.default, options: AVAudioSession.CategoryOptions.defaultToSpeaker)

关于 swift ,AVAudioRecorder : Error 317: ca_debug_string: inPropertyData == NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52182759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com