Error on pausing / resuming / stoping the audio

class AudioSource constructor (
    context: Context
){
    private val mediaRecorder = MediaRecorder(context)
    private val outputFile = File(context.getExternalFilesDir(Environment.DIRECTORY_MUSIC),"sample.mp4")

    fun start(): String? {
        try {
            mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC)
            mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
            mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)
            mediaRecorder.setOutputFile(outputFile)
            mediaRecorder.prepare()
            mediaRecorder.start()
            return "started"
        }catch(error: Exception){
            return error.toString()
        }
    }
    fun pause(): String? {
        try {
            mediaRecorder.pause()
            return "paused"
        }catch(error: RuntimeException){
            return error.toString()
        }
    }
    fun resume(): String? {
        try {
            mediaRecorder.resume()
            return "resumed"
        } catch (error: RuntimeException) {
            return error.toString()
        }
    }
    fun stop(): String? {
        try {
            mediaRecorder.stop()
            return "stopped"
        }catch(error: RuntimeException){
            error.printStackTrace()
            if(outputFile.exists()){
                outputFile.delete()
            }
            return error.toString()
        }finally {
            mediaRecorder.release()
        }
    }
}

getting

java.lang.IllegalStateException error

usage

val mediaRecorder = AudioSource(context = context)

IconButton(
  onClick = {
    if(is_paused.value){
     audio_error.value = mediaRecorder.pause()
   }else {
     audio_error.value = mediaRecorder.resume()
   }
   is_paused.value = !is_paused.value
  }) {}


  IconButton(
    onClick = {
       mic_permission.launchPermissionRequest()
       audio_error.value = mediaRecorder.start()
       if(!is_pressed.value && !is_message && mic_permission.status is PermissionStatus.Granted){
         is_pressed.value = true
       }else if(mic_permission.status is PermissionStatus.Denied){
         val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
         data = Uri.fromParts("package",context.packageName,null)
       }
       context.startActivity(intent)
    }
   }) {}