Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit cbeb8fc4 authored by Luca Stefani's avatar Luca Stefani
Browse files

Recorder: Release the AudioRecord properly

Change-Id: If7c31ad56ac33029e81f1e572f0f0cb9f5894cf1
parent 7bba6821
Loading
Loading
Loading
Loading
+5 −13
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ class HighQualityRecorder : SoundRecording {
    private var pcmConverter: PcmConverter? = null
    private var path: Path? = null
    private var maxAmplitude = 0
    private var thread: Thread? = null
    private val isRecording = AtomicBoolean(false)
    private val trackAmplitude = AtomicBoolean(false)

@@ -49,9 +48,8 @@ class HighQualityRecorder : SoundRecording {
            startRecording()
        }
        isRecording.set(true)
        thread = Thread { recordingThreadImpl() }.apply {
            start()
        }

        Thread { recordingThreadImpl() }.start()
    }

    override fun stopRecording(): Boolean {
@@ -61,11 +59,9 @@ class HighQualityRecorder : SoundRecording {

        isRecording.set(false)

        try {
            thread?.join(1000)
        } catch (e: InterruptedException) {
            // Wait at most 1 second, if we fail save the current data
        }
        record?.stop()
        record?.release()
        record = null

        path?.also {
            pcmConverter?.convertToWave(it)
@@ -150,10 +146,6 @@ class HighQualityRecorder : SoundRecording {
                        isRecording.set(false)
                    }
                }
                record?.let {
                    it.stop()
                    it.release()
                }
            }
        } catch (e: IOException) {
            Log.e(TAG, "Can't find output file", e)