I've got a strange bug in my audio recording app that causes the device to switch to internal audio when I call AudioRecord.startRecording();
Meaning, all audio from every app (music players, YouTube, etc.) gets forced through the speakers from that point on and recording is made from the internal microphone, even if a headset with a microphone is plugged in.
The only way to allow the headset to work again is to exit the app and adjust the phone volume, which seems to cause the device to realize it's got a headset again.
My question is whether anyone can tell me what I might be doing to cause the forced switch to the speakers? Or is it maybe just a problem with the device/rom I'm using to test?
Here is the call that causes the switch:
AudioRecord record = openAudio();
record.startRecording();
...
private AudioRecord openAudio()
{
int samplingRate = Integer.parseInt(prefs.getString("sample_rate", "44100"));
int min = AudioRecord.getMinBufferSize(samplingRate,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT);
Log.d("Recorder", "Min buffer size: " + min);
Log.d("Recorder", "Sampling Rate: " + samplingRate);
if (min < 4096)
min = 4096;
AudioRecord record = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, samplingRate,
AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, min);
if (record.getState() == AudioRecord.STATE_INITIALIZED)
{
// Log.d("Recorder", "Audio recorder initialised at " + record.getSampleRate()); return record; } record.release(); record = null; return null; }
and here is the full app if anyone is interested in testing on their device:
https://play.google.com/store/apps/details?id=org.yuttadhammo.androidwave
https://github.com/yuttadhammo/androidwave
UPDATE: The same behaviour occurs in Rehearsal Assistant as well, but only if I have it record uncompressed audio. It seems that the problem has something to do with recording uncompressed audio. Any ideas why?