In my application i have successfully recorded the audio and now I am 
playing it using following function:

public void playfile()
{
    System.out.println("Play Pressed");     
     speechLength = (int)(file.length()/2);
     speech2 = new short[speechLength];
     try
     {
        // Create a DataInputStream to read the audio data back from the saved 
file.
        InputStream is = new FileInputStream(file);
        BufferedInputStream bis = new BufferedInputStream(is);
        DataInputStream dis = new DataInputStream(bis);

        int i = 0;              
        while(i <  speechLength)
        {
            speech2[i] = dis.readShort();
            i++;
        }

        // Close the input streams.
        is.close();
        bis.close();
        dis.close();  

        // Create a new AudioTrack object using the same parameters as the 
AudioRecord
        // object used to create the file.
        audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                16000, 
                AudioFormat.CHANNEL_OUT_MONO,
                AudioFormat.ENCODING_PCM_16BIT, 
                bufferSizeAT, 
                AudioTrack.MODE_STREAM);   

        //Start playback


        runner.start();
        //Updating Progress Bar on UI Thread
        //updateProgressBar();
     } //main try
    catch (Throwable t){} 
}
 Thread runner= new Thread (){
        public void run()
        {

              // Do stuff.
            audioTrack.play();
            audioTrack.setStereoVolume(50, 50);
            audioTrack.write(speech2, 0, speech2.length);

        }
    };



But when On the button click I want to pause the recording that has been
 playing it pauses , but while on resume nothing happens. Following is 
the code for same:



final Button p3_button=(Button)myView.findViewById(R.id.btn_play);
    p3_button.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View view)
        {       
            if(p3_button.getText()=="Pause")
            {

                p3_button.setText("Resume");
                audioTrack.pause();


            }
            else if(p3_button.getText()=="Resume")
            {
                p3_button.setText("Pause");

                audioTrack.play();


            }
            else
            {
                p3_button.setText("Pause");
                count = 0;
                isPlayPressed = true;
                playing = true;
                playfile();
            }
        }});

Any help would be great. There is not much help on this one on Google. I
 am almost done with my app but now at the last moment I am suffering 
with this issue..Please help me!!


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to