Search code examples
androidaudio-recordingandroid-mediaplayerandroid-mediarecorder

Check to see if Android MediaRecorder is Recording


I've written some code for Android 2.2 that plays an audio file using the Android MediaPlayer. Without getting into the details of the code, I noticed that there exists a function called

isPlaying()

that allows you to check if an audio file is currently being played by the MediaPlayer. So, for example, when the following snippet of code runs

Toast.makeText(getApplicationContext(), "Sound playing is: " +
        mediaPlayer.isPlaying(), Toast.LENGTH_SHORT).show();

it displays the following message

Sound playing is: true / false

depending on whether there's sound playing or not.

When I wrote some code to record sound from the microphone using the Android MediaRecorder, however, I noticed that there did not look like there exists a function called

isRecording()

that checks to see whether a recording is in progress.

So, I was wondering if the onus is on the programmer then to figure out if a recording is in progress by embedding some logic into their code - or if perhaps there indeed exists a way to do this (check if a recording is in progress) by using another in-built function offered by the Android API.


Solution

  • Doesn't look like there is such a function after all. I think it makes sense to try to embed some logic in the code to do this cleanly.