NaraeAudioRecorder
NaraeAudioRecorder copied to clipboard
stop() called on an uninitialized AudioRecord
After i called stopRecording(), I got this error and can't find my recording file.
Can I get sample code that I can reproduce?
[class AudioManager(private val mContext: Context, private val mFileName: String, private val mMaxTime: Long, private val listener: OnTimerCountListener) { private val tag = "AudioManager"
private val mDestFile = File(mFileName)
private val mRecorder: NaraeAudioRecorder by lazy {
val audioRecorder = NaraeAudioRecorder()
mDestFile.parentFile?.let {
File(mDestFile.parent).mkdirs()
}
mDestFile.createNewFile()
audioRecorder.create(FFmpegRecordFinder::class.java) {
this.maxAvailableMillis = TimeUnit.MINUTES.toMillis(mMaxTime)
this.timerCountListener = listener
this.destFile = destFile
this.debugMode = true
this.recordConfig = defaultConfig()
this.audioSource = DefaultAudioSource(defaultConfig())
}
(audioRecorder.getAudioRecorder() as FFmpegAudioRecorder).apply {
setContext(mContext)
setOnConvertStateChangeListener {
LogUtil.d(tag, "state: ${it.toString()}")
}
}
audioRecorder
}
private fun defaultConfig() = AudioRecordConfig(MediaRecorder.AudioSource.MIC,
AudioFormat.ENCODING_PCM_16BIT,
AudioFormat.CHANNEL_IN_MONO,
AudioConstants.FREQUENCY_44100)
fun startRecord() = mRecorder.startRecording(mContext)
fun pauseRecord() {
mRecorder.pauseRecording()
}
fun resumeRecord() {
mRecorder.resumeRecording()
}
fun stopRecord() {
mRecorder.stopRecording()
}
fun restRecord(){
mRecorder.pauseRecording()
mDestFile.deleteOnExit()
}
}](url)
This is my sample code, I invoke startRecord() method first, After a short time, I invoke stopRecord(), Then i will get that error and can't find my recording file.