• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Playing Audio Through Earpiece

xtro786

Lurker
Sep 26, 2010
2
0
Hello,

I am developing an application on an HTC Desire under Android v2.2. I would like to play some audio through the ear piece of the phone and not the speaker. I cannot seem to find a way to do this. I am using the AudioTrack class to play a raw audio file as follows:

// Create AudioTrack object using the same parameters as the AudioRecord
// object used to create the file.
AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
musicLength,
AudioTrack.MODE_STREAM);

// Start playback
audioTrack.play();

// Write the music buffer to the AudioTrack object
audioTrack.write(music, 0, musicLength);




The audio plays fine out of the speaker phone, but I cannot find a way to play the audio through the phone's ear piece. Does anyone know how to do this?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones