Playing Audio Through Earpiece


Last Updated:

  1. xtro786

    xtro786 New Member This Topic's Starter

    Joined:
    Sep 26, 2010
    Messages:
    2
    Likes Received:
    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?
     

    Advertisement
  2. xtro786

    xtro786 New Member This Topic's Starter

    Joined:
    Sep 26, 2010
    Messages:
    2
    Likes Received:
    0
    Surely someone has run into this before?
     
  3. txosky

    txosky New Member

    Joined:
    Oct 17, 2010
    Messages:
    1
    Likes Received:
    0
    Hi xtro786!

    I
     
  4. mohitjaitly

    mohitjaitly Active Member

    Joined:
    Oct 18, 2010
    Messages:
    34
    Likes Received:
    0

Share This Page

Loading...