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

  • SEARCH
  • Home
  • 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 6769863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:14:38+00:00 2026-05-26T15:14:38+00:00

package com.Project_recording; import java.io.File; import java.io.IOException; import android.app.Activity; import android.media.MediaPlayer; import android.media.MediaRecorder; import android.os.Bundle;

  • 0
package com.Project_recording;

import java.io.File;
import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Project_recordingActivity extends Activity {
    private static final String APP_TAG = "com.hascode.android.soundrecorder";

    private MediaRecorder recorder = new MediaRecorder();
    private MediaPlayer player = new MediaPlayer();

    private Button btRecord;
    private Button btPlay;
    private TextView resultView;

    private boolean recording = false;
    private boolean playing = false;
    private File outfile = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        resultView = (TextView) findViewById(R.id.output);

        try {
            // the soundfile
            File storageDir = new File(Environment
                    .getExternalStorageDirectory(), "com.hascode.recorder");
            storageDir.mkdir();
            Log.d(APP_TAG, "Storage directory set to " + storageDir);
            outfile = File.createTempFile("hascode", ".3gp", storageDir);

            // init recorder
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            recorder.setOutputFile(outfile.getAbsolutePath());

            // init player
            player.setDataSource(outfile.getAbsolutePath());
        } catch (IOException e) {
            Log.w(APP_TAG, "File not accessible ", e);
        } catch (IllegalArgumentException e) {
            Log.w(APP_TAG, "Illegal argument ", e);
        } catch (IllegalStateException e) {
            Log.w(APP_TAG, "Illegal state, call reset/restore", e);
        }

        btRecord = (Button) findViewById(R.id.btRecord);
        btRecord.setOnClickListener(handleRecordClick);

        btPlay = (Button) findViewById(R.id.btPlay);
        btPlay.setOnClickListener(handlePlayClick);

    }

    private final OnClickListener handleRecordClick = new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (!recording) {
                startRecord();
            } else {
                stopRecord();
            }
        }
    };

    private final OnClickListener handlePlayClick = new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (!playing) {
                startPlay();
            } else {
                stopPlay();
            }
        }
    };

    private void startRecord() {
        Log.d(APP_TAG, "start recording..");
        printResult("start recording..");
        try {
            recorder.prepare();
            recorder.start();
            recording = true;
        } catch (IllegalStateException e) {
            Log
                    .w(APP_TAG,
                            "Invalid recorder state .. reset/release should have been called");
        } catch (IOException e) {
            Log.w(APP_TAG, "Could not write to sd card");
        }
    }

    private void stopRecord() {
        Log.d(APP_TAG, "stop recording..");
        printResult("stop recording..");
        recorder.stop();
        recorder.reset();
        recorder.release();
        recording = false;
    }

    private void startPlay() {
        Log.d(APP_TAG, "starting playback..");
        printResult("start playing..");
        try {
            playing = true;
            player.prepare();
            player.start();
        } catch (IllegalStateException e) {
            Log.w(APP_TAG, "illegal state .. player should be reset");
        } catch (IOException e) {
            Log.w(APP_TAG, "Could not write to sd card");
        }
    }

    private void stopPlay() {
        Log.d(APP_TAG, "stopping playback..");
        printResult("stop playing..");
        player.stop();
        player.reset();
        player.release();
        playing = false;
    }

    private void printResult(String result) {
        resultView.setText(result);
    }
}

When I press the record button, Is starts recording. When I press the play button, It starting playing. When I again press the play button, I stops playing. The important issue which I am facing is the sound is not heared..? Please do me a needful. I am new to android..

  • 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-05-26T15:14:39+00:00Added an answer on May 26, 2026 at 3:14 pm

    Why you are resetting the recorder object immediately after recording .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package com.ustr.eMIRnew; import java.util.ArrayList; import java.util.HashMap; import android.R; import android.app.Activity; import android.os.Bundle; import android.widget.ListView;
package com.android.project; import android.app.Activity; import android.os.Bundle; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE;
I am interested in using a class file (CameraPreview.java) from this package com.example.android.apis.graphics. I
The error I'm receiving is listed here . That's my HibernateUtil.java package com.rosejapan; import
Please consider the following java source: package com.stackoverflow; public class CondSpeed { private static
I have an aidl file defined as follows: package com.erbedo.callalert; interface RemoteCallAlert { void
Let's say I have a file called test.txt within the package com.test.io within my
I have my source in the hierarchy: folder: src/main/java package: com.test.serviceImpl Now eclipse is
here is my code, package com.mjzone.project; public class MyDatabase extends Activity { final protected
I have a java project with class having main method in package com.nik.mypackage. Only

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.