On Saturday, April 30, 2016 at 2:30:27 PM UTC-4, Nilesh Darade wrote: > > My code to take audio recorder. > > Anything I missing? > > > I know following code is not upto mark but I tried to extract what I have in > the code. > > > > public static AudioRecord findAudioRecord(Context context) { > AudioRecord recorder = null; > try { > AudioManager audioManager = (AudioManager) > context.getSystemService(Context.AUDIO_SERVICE); > int _rate = > Integer.parseInt(audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE)); > //int bufferSize = > Integer.parseInt(audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER)); > for (short audioFormat : new short[]{AudioFormat.ENCODING_PCM_8BIT, > AudioFormat.ENCODING_PCM_16BIT}) { > for (short channelConfig : new > short[]{AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO}) { > > Log.d(TAG, "Attempting rate " + _rate + "Hz, bits: " + > audioFormat + ", channel: " > + channelConfig); > int bufferSize = AudioRecord.getMinBufferSize(_rate, > channelConfig, audioFormat); > if (bufferSize != AudioRecord.ERROR_BAD_VALUE) { > // check if we can instantiate and have a success > recorder = new > AudioRecord(MediaRecorder.AudioSource.DEFAULT, _rate, channelConfig, > audioFormat, bufferSize); > > if (recorder.getState() == AudioRecord.STATE_INITIALIZED) > { > _bufferSize = bufferSize; > return recorder; > } > } > > } > } > } catch (Exception e) { > Log.e(TAG, "Exception, keep trying.", e); > } > > // I'm removing above configurations (_rate) from below code... > > > for (int rate : new int[]{8000, 11025, 16000, 22050, 44100}) { > for (short audioFormat : new short[]{AudioFormat.ENCODING_PCM_8BIT, > AudioFormat.ENCODING_PCM_16BIT}) { > for (short channelConfig : new > short[]{AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO}) { > try { > Log.d(TAG, "Attempting rate " + rate + "Hz, bits: " + > audioFormat + ", channel: " > + channelConfig); > bufferSize = AudioRecord.getMinBufferSize(rate, > channelConfig, audioFormat); > > if (bufferSize != AudioRecord.ERROR_BAD_VALUE) { > // check if we can instantiate and have a success > recorder = new > AudioRecord(MediaRecorder.AudioSource.DEFAULT, rate, channelConfig, > audioFormat, bufferSize); > > if (recorder.getState() == > AudioRecord.STATE_INITIALIZED) { > _bufferSize = bufferSize; > return recorder; > } > } > } catch (Exception e) { > Log.e(TAG, rate + "Exception, keep trying.", e); > } > } > } > } > return null; > } > > > > > > I test drove your 2nd code snippet and found it worked on all configurations with the exception that any 8 bit attempt would always fail.
This confirms what I found with various tablets and phones. If your Samsung tablet is failing on all attempts try changing MediaRecorder.AudioSource.*DEFAULT* to MediaRecorder.AudioSource.MIC If you want a separate baseline, test drive my VoIP app, it lets you test microphone input to speaker output dynamically when configuring the voice codec. https://play.google.com/store/apps/details?id=threezwireless.com.mobilevoicertp -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. To post to this group, send email to android-developers@googlegroups.com. Visit this group at https://groups.google.com/group/android-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/dace2f00-5185-4eff-ad8b-c29ba738c80d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.