Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to stop sound input and output from changing to internal when recording audio in Android?
    primarykey
    data
    text
    <p>I've got a strange bug in my audio recording app that causes the device to switch to internal audio when I call <code>AudioRecord.startRecording();</code> 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. </p> <p>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.</p> <p>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?</p> <p>Here is the call that causes the switch:</p> <pre><code> AudioRecord record = openAudio(); record.startRecording(); </code></pre> <p>...</p> <pre><code> 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 &lt; 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) { </code></pre> <p>// Log.d("Recorder", "Audio recorder initialised at " + record.getSampleRate()); return record; } record.release(); record = null; return null; }</p> <p>and here is the full app if anyone is interested in testing on their device:</p> <p><a href="https://play.google.com/store/apps/details?id=org.yuttadhammo.androidwave" rel="nofollow">https://play.google.com/store/apps/details?id=org.yuttadhammo.androidwave</a></p> <p><a href="https://github.com/yuttadhammo/androidwave" rel="nofollow">https://github.com/yuttadhammo/androidwave</a></p> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload