我们正在使用AudioRecord录制音频,并使用库将录制内容显示为波形。录制音频和显示波形的代码发布在下面。但出于某种原因,我在1处收到此错误。有人可以帮助我解决此问题吗?这个应用程序在应用程序上线后的3个月内发生了一次,但是想了解这个问题并为此修复了问题。
这在Android 5.1.1设备中已经发生了
inner class RecordingThread : Thread() {
var mShouldContinue = true;
override fun run() {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO)
val recorder = AudioRecord(MediaRecorder.AudioSource.VOICE_RECOGNITION, RECORDING_SAMPLE_RATE,
AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, byteBufferSize)
try {
recorder.startRecording()
while (shouldContinue()) {
recorder.read(audioByteBuffer, 0, byteBufferSize)
Thread({
val buffer = ByteBuffer.wrap(audioByteBuffer)
buffer.order(ByteOrder.LITTLE_ENDIAN)
buffer.put(audioByteBuffer)
try {
output?.write(buffer.array())
} catch (exception: Exception) {
error(exception)
}
}).start() ----------------------------- Error at this place
Thread({
val shorts = kotlin.ShortArray(byteBufferSize/2)
ByteBuffer.wrap(audioByteBuffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts);
recordingWaveform?.updateAudioData(shorts)
}).start()
}
} catch (e: IllegalStateException) {
error(e)
} finally {
recorder.stop()
recorder.release()
}
}
/**
* Gets a value indicating whether the thread should continue running.
* @return true if the thread should continue running or false if it should stop
*/
@Synchronized private fun shouldContinue(): Boolean {
return mShouldContinue
}
/** Notifies the thread that it should stop running at the next opportunity. */
@Synchronized fun stopRunning() {
mShouldContinue = false
}
}