EZAudio 不起作用:创建 EZRecorder 实例时的 Thread1 EXC_BAD_ACCESS
Posted
技术标签:
【中文标题】EZAudio 不起作用:创建 EZRecorder 实例时的 Thread1 EXC_BAD_ACCESS【英文标题】:EZAudio doesnt work: Thread1 EXC_BAD_ACCESS while creating EZRecorder instance 【发布时间】:2016-12-12 15:03:55 【问题描述】:我对@987654324@的完整实现:
class ViewController: UIViewController, EZMicrophoneDelegate, EZRecorderDelegate
@IBOutlet var recordingAudioPlot: EZAudioPlot!
private var isRecording = false
didSet
if isRecording
player.pause()
recordingAudioPlot.clear()
microphone.startFetchingAudio()
recorder = EZRecorder(url: filePathUrl(), clientFormat: microphone.audiostreamBasicDescription(), fileType: EZRecorderFileType.M4A, delegate: self)
// ** Here is where the error occurs **
else
recorder.delegate = nil
microphone.stopFetchingAudio()
recorder.closeAudioFile()
player.playAudioFile(EZAudioFile(url: filePathUrl()))
private var microphone = EZMicrophone()
private var recorder = EZRecorder()
private var player = EZAudioPlayer()
@IBAction func startStopRecordingButtonTapped(_ sender: UIButton)
isRecording = !isRecording
override func viewDidLoad()
super.viewDidLoad()
let session = AVAudioSession.sharedInstance()
try! session.setCategory(AVAudioSessionCategoryPlayAndRecord)
try! session.setActive(true)
microphone.delegate = self
try! session.overrideOutputAudioPort(.speaker)
func microphone(_ microphone: EZMicrophone!, hasAudioReceived buffer: UnsafeMutablePointer<UnsafeMutablePointer<Float>?>!, withBufferSize bufferSize: UInt32, withNumberOfChannels numberOfChannels: UInt32)
DispatchQueue.main.async
self.recordingAudioPlot.updateBuffer(buffer[0], withBufferSize: bufferSize)
func microphone(_ microphone: EZMicrophone!, hasBufferList bufferList: UnsafeMutablePointer<AudioBufferList>!, withBufferSize bufferSize: UInt32, withNumberOfChannels numberOfChannels: UInt32)
if isRecording
recorder.appendData(from: bufferList, withBufferSize: bufferSize)
private func filePathUrl() -> URL
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first ?? ""
return URL(fileURLWithPath: String(format: "%@/%@", path, "pathtofile.m4a"))
错误如下:
出了什么问题?
【问题讨论】:
您是否检查过所有变量是否设置正确,尤其是 filePathURL 和 asbd ? filePathUrl 是正确的...什么是 asbd? audiostreambasicdescription... 第二个参数,一般来说:您正在尝试访问该上下文中不再存在的内存地址上的对象...因此请检查哪些对象可能不存在存在的...在 xcodes 调试器视图中应该很容易做到 但我从示例中得到它......它在那里工作......看看这里:github.com/syedhali/EZAudio/blob/master/EZAudioExamples/iOS/… @Volker 好的,我会在一小时内打印出来并通知您... 【参考方案1】:解决方案是将recorder
声明为可选类型,而不是实例:
private var recorder: EZRecorder?
当它第一次尝试解除分配第一个初始化的记录器时发生了一些事情......但现在有 nil
所以错误不再存在。
【讨论】:
以上是关于EZAudio 不起作用:创建 EZRecorder 实例时的 Thread1 EXC_BAD_ACCESS的主要内容,如果未能解决你的问题,请参考以下文章