1. Check out our companion app, Forums for Android! Download from Google Play

Playing Audio Through Earpiece

Discussion in 'Application Development' started by xtro786, Sep 26, 2010.

  1. xtro786

    xtro786 New Member
    Thread Starter
    5

    Sep 26, 2010
    2
    0
    5
    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
    Thread Starter
    5

    Sep 26, 2010
    2
    0
    5
    Surely someone has run into this before?
     
  3. txosky

    txosky New Member
    5

    Oct 17, 2010
    1
    0
    5
    Hi xtro786!

    I
     

Share This Page

Loading...