Search code examples
javaandroidaudiorecordandroid-audiorecord

Stop button when recording audio with AudioRecord


At the moment I have the code from this site (link text) working great. In the example on the site it starts the recording for 10 seconds and then immediately plays the audio back in reverse. I have modified the code to start recording when a button is pressed, but can only get it to record for the 10 seconds and then save that file. I want to be able to start the recording by pressing a button and then stop the recording on a different button press. I have an idea that it could be an interrupt to the wait() method of the thread object but have no idea how to implement this. My code is as follows:

public void onClickRecord(View v){
        text.setText("Recording");
        Thread thread = new Thread(new Runnable() {
            public void run() {
                record();
            }
        });

        thread.start();

        synchronized(this) {
        try {
            wait(10000); //This is the 10 second waiting period while recording
        } 
        catch (InterruptedException e) {
        }
        }

        isRecording = false;

        try {
            thread.join();
        } catch (InterruptedException e) {
        }

    }
    public void onClickStop(View v){
        //Here is what needs to be implemented to stop the recording.
    }

There is quite a bit of code so I have only posted the bits I think are relevant. If any more is needed just ask.

Thanks.


Solution

  • try the AudioRecord Class ! I think that should be helpful.

    Also look at AudioCapture here http://developer.android.com/guide/topics/media/index.html