Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8078749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:53:47+00:00 2026-06-05T15:53:47+00:00

I have two buttons, one for start recording and another for stop recording. i

  • 0

I have two buttons, one for start recording and another for stop recording.
i got success in recording sound and storing in sdcard:

now what i want is if i press stop button before 15 sec i should remain as it is, but if recording time going more then 15 sec it should automatically stop recording and store recorded file in sd card:

my code for recording sound is here :

**

public void startRecording(View view) throws IOException {
        startButton.setEnabled(false);
        stopButton.setEnabled(true);
        File sampleDir = Environment.getExternalStorageDirectory();
        try {
            //audiofile = File.createTempFile("sound", ".aac", sampleDir);
            audiofile = File.createTempFile("sound", ".m4a", sampleDir);
        } catch (IOException e) {
            Log.e(TAG, "sdcard access error");
            return;
        }
        recorder = new MediaRecorder();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        recorder.setOutputFile(audiofile.getAbsolutePath());
        recorder.prepare();
        recorder.start();


    }

**

and for stopping recording is

public void stopRecording(View view) {

        startButton.setEnabled(true);
        stopButton.setEnabled(false);
        recorder.stop();
        recorder.release();

    } 

what should i do ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:53:49+00:00Added an answer on June 5, 2026 at 3:53 pm

    Basically you will need to implement TimeTask for that.

     if (view.getId() == R.id.stop) {
                new Timer().schedule(new TimerTask() {
    
                    @Override
                    public void run() {
                        runOnUiThread(new Runnable() {    
                            @Override
                            public void run() {
                                mediaRecorder.stop();
                                mediaRecorder.reset();
                                mediaRecorder.release();
                            }
                        });
    
                    }
    
                }, 15000); //<-- Execute code after 15000 ms i.e after 15 Seconds.
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have two buttons. Each one needs to produce a different sound.
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have a simple form with two buttons (Start and Stop) and a DataGridView.
If I have two buttons, one to start a song being played and one
I have two buttons Start and Pauseand one Textview. The problem I have is
In Application i have two buttons in which one button is used as a
I have two radio buttons next to each other, and even though each one
I have two radio buttons each with a unique ID. When one is clicked,
I am trying to have two submit buttons in my form - one accepts
I have a page with two buttons, one Button opens a popup window with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.