Android - Getting audio to play through earpiece -


I currently have a code that reads a recording from the Device Mike using the AudioRecord class, and then using Audiotrack It runs back

My problem is that when I play it, this speaker plays through the phone.

I want to play it through a piece of ear on the device.

Here is my code:

  Expands the public square LoopProg activity [Boolean isRecording; // Audio Manager is not currently used; Int count = 0; /** Called when the activity is first created. * / @ Override Crate on Public Zero (Bundle Saved Instantstate) {Super. Contents (Saved Instantstate); SetContentView (R.layout.main); Am = (AudioManager) getSystemService (reference. AUDIO_SERVICE); Am.setMicrophoneMute (right); While (calculations & lt; = 1000000) {record record = new record (); Record.run (); Count ++; Log D. ("COUNT" is "calculated:" + count); }} Expands the public class record thread {Static Final Info Buffer Size = 200000; Last short [] buffer = new small [buffer size]; Small [] readBuffer = new small [buffer size]; Public Zero Run () {isRecording = true; Android.os.Process.setThreadPriority (android.os.Process.THREAD_PRIORITY_URGENT_AUDIO); Int buffers = audio record Getimin buffer size (11025, audio format .CHANNEL_CONFIGURATION_MONO, audio format. NCODIDIGCDC 666); AudioRecord ISC = New AudioCard (Media Records., Audio Essars, MIC, 11025, AudioFormat .CHANNEL_CONFIGURATION_MONO, Audio Format. NCOD IDIPIB 66, Beepersz); Audiotrack Atac = New Audiotrack (Audio Manager. STREAM_MUSIC, 11025, Audio Format. CHANNEL_CONFIGURATION_MONO, Audio Format. NCODIDIDI 66 BIT, Buffersize, Audiotrake. MODE_STREAM); Am.setrouting (AudioManager.MODE_NORMAL, 1, AudioManager.STREAM_MUSIC); Int OK = am.getRouting (AudioManager.ROUTE_EARPIECE); Log D. ("Routing", "getRouting =" + OK); SetVolumeControlStream (AudioManager.STREAM_VOICE_CALL); //am.setSpeakerphoneOn(true); Log D. ("Speakerphone", "What's on the speakerphone ?:" + Am.isSpeakerphoneOn ()); Am.setSpeakerphoneOn (wrong); Log D. ("Speakerphone", "What's on the speakerphone ?:" + Am.isSpeakerphoneOn ()); Atrack.setPlaybackRate (11025); Byte [] buffer = new byte [buffers]; Arec.startRecording (); Atrack.play (); While (isrecording) {arec.read (buffer, 0, buffers); Atrack.write (buffer, 0, buffer lamps); } Arec.stop (); Atrack.stop (); IsRecording = false; }}}  

As you can see, I used the audio manager class and the code used in that manner, which has not worked out the offsetting method and nothing worked, setSpeakerphoneOn method There is no effect, neither is the routing method.

Has anybody found out how to play it through the earpiece instead of the spark phone?

Just got to work on 2.2 I still need an inkl setup which I really do not like, but I'll settle it for now. I was able to finish the call routing stuff which is now disliked. I think that you definitely need Modify_Audio_Settings permission, there is no error without it, but this setSpeakerPhone method does not do anything here. Has made a fake uptake.

  Private Audio Manager m_amAudioManager; M_amAudioManager = (AudioManager) getSystemService (reference. AUDIO_SERVICE); M_amAudioManager.setMode (AudioManager.MODE_IN_CALL); M_amAudioManager.setSpeakerphoneOn (wrong);  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -