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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:24:13+00:00 2026-06-04T01:24:13+00:00

I am trying to develop app, which records audio & playback.I am able to

  • 0

I am trying to develop app, which records audio & playback.I am able to record & play recorded files. Now i want to display recording time while recording audio or sound. Searched google & many things not able to get it any idea. can anybody say me how to proceed next steps.

here is my code for audio recording with timer

public class AudioRecordActivity extends Activity implements OnClickListener {

MediaRecorder recorder = new MediaRecorder();
private String fileName;
private Button record;
private Button play;
private Button stop;
private TextView timeDisplay;
Chronometer myChronometer;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    record = (Button) findViewById(R.id.recordButton);
    record.setOnClickListener(this);

    play = (Button) findViewById(R.id.playButton);
    play.setOnClickListener(this);

    stop = (Button) findViewById(R.id.stopButton);
    stop.setOnClickListener(this);

    myChronometer = (Chronometer) findViewById(R.id.timer);
    record.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            myChronometer.start();
        }
    });

    stop.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            myChronometer.stop();

        }
    });
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.recordButton:
        try {

            stop.setEnabled(true);
            record.setEnabled(false);

            startRecording();
        } catch (IOException e) {
            System.out.println(e + "");
            e.printStackTrace();
        }
        break;
    case R.id.stopButton:

        stop.setEnabled(false);
        record.setEnabled(true);
        stopRecording();

        break;

    case R.id.playButton:
        Intent intent = new Intent();
        // PLAY ANY AUDIO/VIDEO FILE
        intent.setAction(android.content.Intent.ACTION_VIEW);
        File file = new File("/sdcard/" + fileName);
        intent.setDataAndType(Uri.fromFile(file), "audio/*");
        startActivity(intent);
        break;

    default:
        break;
    }

}

void startRecording() throws IOException {
    SimpleDateFormat timeStampFormat = new SimpleDateFormat(
            "yyyy-MM-dd-HH.mm.ss");
    // fileName = "audio_" + timeStampFormat.format(new Date()) + ".mp4";
    fileName = "audioTest" + ".mp4";

    recorder = new MediaRecorder();

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

    recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);

    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    recorder.setOutputFile("/sdcard/" + fileName);

    recorder.setAudioEncodingBitRate(320);
    recorder.setAudioSamplingRate(16000);
    recorder.setAudioChannels(2);
    recorder.prepare();

    recorder.start();

}

private void stopRecording() {
    if (null != recorder) {
        try {
            recorder.stop();
            recorder.reset();
            recorder.release();
            recorder = null;
        } catch (NullPointerException e) {
            Toast.makeText(getApplicationContext(),
                    "Recording not started", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }
    }
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if (KeyEvent.KEYCODE_BACK == keyCode) {
        finish();
    }
    return super.onKeyDown(keyCode, event);
}
}

Here My logcat error

05-16 16:11:11.603: E/AndroidRuntime(21256): FATAL EXCEPTION: main
05-16 16:11:11.603: E/AndroidRuntime(21256): java.lang.RuntimeException: Unable to start     activity ComponentInfo{xxx.com/xxx.com.AudioRecordActivity}:    java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Chronometer
05-16 16:11:11.603: E/AndroidRuntime(21256):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at android.os.Looper.loop(Looper.java:137)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at android.app.ActivityThread.main(ActivityThread.java:4424)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at java.lang.reflect.Method.invokeNative(Native Method)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at java.lang.reflect.Method.invoke(Method.java:511)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at dalvik.system.NativeStart.main(Native Method)
05-16 16:11:11.603: E/AndroidRuntime(21256): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Chronometer
05-16 16:11:11.603: E/AndroidRuntime(21256):    at xxx.com.AudioRecordActivity.onCreate(AudioRecordActivity.java:45)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at android.app.Activity.performCreate(Activity.java:4465)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-16 16:11:11.603: E/AndroidRuntime(21256):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)

Thanks…

  • 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-04T01:24:14+00:00Added an answer on June 4, 2026 at 1:24 am

    for this you should try Chronometer, by this you can fulfill your goal good luck

    sample code of Chronometer is here :

    in main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      >
    <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/hello"
      />
    <Chronometer
     android:id="@+id/chronometer"
     android:layout_gravity="center_horizontal"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
     />
    <Button
     android:id="@+id/buttonstart"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="Start"
     />
    <Button
     android:id="@+id/buttonstop"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="Stop"
     />
    <Button
     android:id="@+id/buttonreset"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="Reset"
     />
    </LinearLayout>
    

    in java file

    package com.exercise.AndroidChronometer;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.os.SystemClock;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Chronometer;
    
    public class AndroidChronometer extends Activity {
       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.main);
    
           final Chronometer myChronometer = (Chronometer)findViewById(R.id.chronometer);
           Button buttonStart = (Button)findViewById(R.id.buttonstart);
           Button buttonStop = (Button)findViewById(R.id.buttonstop);
           Button buttonReset = (Button)findViewById(R.id.buttonreset);
    
           buttonStart.setOnClickListener(new Button.OnClickListener(){
    
       @Override
       public void onClick(View v) {
        // TODO Auto-generated method stub
        myChronometer.start();
       }});
    
           buttonStop.setOnClickListener(new Button.OnClickListener(){
    
       @Override
       public void onClick(View v) {
        // TODO Auto-generated method stub
        myChronometer.stop();
    
       }});
    
           buttonReset.setOnClickListener(new Button.OnClickListener(){
    
       @Override
       public void onClick(View v) {
        // TODO Auto-generated method stub
        myChronometer.setBase(SystemClock.elapsedRealtime());
    
       }});
    
    
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying develop an Android app which uses Google maps. So for the
I am trying to develop a Qt App using 4.7.3 which involves the writing
I have been trying to develop an app for my ipad which i can
I'm trying to develop an app which first checks if the device is connected
I am trying to develop an android app, where user should be able to
I'm trying to develop an app which uses the Camera. So far it's been
I am trying to develop a web app which applies an appropriate style sheet
I am trying to develop an iphone app in which matrix of jewel. if
I am trying to develop a small app BusTracker which will list down a
I'm trying to develop an app which allows you to walk around, and where

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.