Hey, I'm trying to create a voice recording on the...
# multiplatform
a
Hey, I'm trying to create a voice recording on the KMM application and I faced an issue with initializing the
AVAudioRecorder
on the Kotlin side, maybe someone already faced that issue and was able to resolve it ? Thanks! Details are in 🧵
✅ 1
My Kotlin code for iOS:
Copy code
private fun createRecorder(url: NSURL, error: CPointer<ObjCObjectVar<NSError?>>?): AVAudioRecorder {
        val settings = mapOf<Any?, Any?>(
            AVFormatIDKey to kAudioFormatMPEG4AAC.toInt(),
            AVSampleRateKey to 12000,
            AVNumberOfChannelsKey to 1,
            AVEncoderAudioQualityKey to AVAudioQualityHigh
        )
        Napier.d { "Url is $url, ${url.path}" }
        return AVAudioRecorder(url, settings, error)
    }
The URL I'm passing looks like:
file:///Users/andriiyanechko/Library/Developer/CoreSimulator/Devices/B0099A9D-D13E-441F-85B4-51F4A7BDE4B1/data/Containers/Data/Application/E4EF69B8-5E54-42B3-9E92-1B843D684B08/Documents/8A79AA3F-B44E-4EDE-A6F8-5B58DC52CB72-AnimalNameRecording.m4a
I'm invoking that function from the Main thread and getting this error:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x50)
If I write same code but on the Swift it works and recording is getting started:
Copy code
let url = getDocumentsDirectory().appendingPathComponent("\(UUID().uuidString)-recording.m4a")
print(url)
let audioFilename = url
let settings = [
   AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
   AVSampleRateKey: 12000,
   AVNumberOfChannelsKey: 1,
   AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
]

do {
   let audioRecorder = try AVAudioRecorder(url: audioFilename, settings: settings)
   audioRecorder.delegate = self
   audioRecorder.record()
   print("Recording...")                 
} catch {
   print("Error")
}
Screenshot 2023-06-25 at 12.53.38 PM.png
Sorry, I was using the memScoped in a wrong way - ✅
450 Views