mercredi 24 décembre 2014

AudioTrack cannot play audio to speaker in mobile

I am new member of Android and I have a problem that need your help. I am making a project that can play the sound that coming from headset Bluetooth. I am using SCO to receive and AudioTrack to play during receiving. The receiving task is done. But the playtask help some problem is that I cannot hear the sound in the speaker of mobile (only hear in earphone of headset device), although I set



_audioManager.setSpeakerphoneOn(true);


For playing task I used this code



_audioManager.startBluetoothSco();
_audioManager.setMode(AudioManager.STREAM_MUSIC);
_audioManager.setSpeakerphoneOn(true);
recorder = new AudioRecord(MediaRecorder.AudioSource.VOICE_COMMUNICATION,
RECORDER_SAMPLERATE, RECORDER_CHANNELS,
RECORDER_AUDIO_ENCODING, BufferElements2Rec * BytesPerElement);
int maxJitter = AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
track = new AudioTrack(AudioManager.MODE_IN_COMMUNICATION, 8000, AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT, maxJitter, AudioTrack.MODE_STREAM);

track.play();
recorder.read(sData, 0, BufferElements2Rec);
try {
// // writes the data to file from buffer
byte bData[] = short2byte(sData);
track.write(bData, 0, BufferElements2Rec * BytesPerElement);
} catch (IOException e) {
e.printStackTrace();
}


This is my full code. Please run it and let me know the problem link


Aucun commentaire:

Enregistrer un commentaire