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 6818137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:08:26+00:00 2026-05-26T21:08:26+00:00

i’ve been trying to record and play recorded audio in android . I’ve used

  • 0

i’ve been trying to record and play recorded audio in android . I’ve used MediaRecorder and MediaPlayer class for the same.

My code contain 3 segments:
startrecording()
stoprecording()
playaudio

But there’s an error in my code fragement and whenever i execute it ,the startrecording() function implements catch block.

 package hare.krishna;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;


public class Recordplay2Activity extends Activity 
{    
    Button play1,record1,stop1;
    TextView status1;
    MediaRecorder m1=null;
    MediaPlayer m2=null;
    String path;

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        play1=(Button)findViewById(R.id.play);
        record1=(Button)findViewById(R.id.record);
        stop1=(Button)findViewById(R.id.stop);
        status1=(TextView)findViewById(R.id.status);

        OnClickListener recordListener = new OnClickListener()
        {
            public void onClick(View v)
            {
                startrecording();
            }
        };

        OnClickListener stopListener = new OnClickListener()
        {
            public void onClick(View v)
            {
                stoprecording();
            }
        };

        OnClickListener playListener = new OnClickListener()
        {
            public void onClick(View v)
            {
                playaudio();
            }
        };

        record1.setOnClickListener(recordListener);
        stop1.setOnClickListener(stopListener); 
        play1.setOnClickListener(playListener);    

    }


    public void startrecording() 
    {       
        status1.setText("GET READY FOR RECORDING");
        try
        {       
        m1=new MediaRecorder();
        m1.setAudioSource(MediaRecorder.AudioSource.MIC);
        m1.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        m1.setOutputFile(path);
        m1.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

        m1.prepare();
        m1.start();
        }
        catch(Exception e)
        {
            status1.setText("ERROR IN startrecording FUNCTION ");
        }
    }

    public void stoprecording()
    {
        try
        {
        status1.setText("TIME TO STOP MEDIA");
        m1.stop();
        m1.reset();
        m1.release();
        }
        catch(Exception e)
        {
            status1.setText("ERROR IN stoprecording FUNCTION");
        }
    }

    public void playaudio()
    {
        status1.setText("PLAYING RECORDER AUDIO");
        try
        {
            m2=new MediaPlayer();
            m2.setDataSource("/sdcard/output.3gp");
            m2.prepare();
            m2.start();

        }
        catch(Exception e)
        {
            System.out.println("ERROR in playaudio FUNCTION");

        }
    }



}
  • 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-26T21:08:27+00:00Added an answer on May 26, 2026 at 9:08 pm

    I solved it. I changed AudioEncoder from:

    m1.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)
    

    to:

    m1.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.