1

recently when I record button click, start camera preview and digital clock view record

but, when I showing my record video. not showing digitalclock.

only GLSurfaceView camera preview display.

perhaps, If you've ever added a clock on recorded video,

please advice for me

thanks.

chohyunwook
  • 411
  • 1
  • 5
  • 18

1 Answers1

0

Try this answer ,Thanks to him

    import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

public class VideoRD extends Activity implements OnClickListener,
        SurfaceHolder.Callback {
    MediaRecorder recorder;
    SurfaceHolder holder;

    boolean recording = false;
    public static final String TAG = "VIDEOCAPTURE";
    String str_getValue ;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        Intent i1 = getIntent();
        str_getValue = i1.getStringExtra("videoImagename");
        recorder = new MediaRecorder();
        initRecorder();
        setContentView(R.layout.surface);


        SurfaceView cameraView = (SurfaceView) findViewById(R.id.CameraView);
        holder = cameraView.getHolder();
        holder.addCallback(this);
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

        cameraView.setClickable(true);
        cameraView.setOnClickListener(this);

        final Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
                if (recording) {
                    try {
                        recorder.stop();
                        recorder.release();
                        recording = false;
                        Log.v(TAG, "Recording Stopped");
                        initRecorder();
                        prepareRecorder();

                    } catch (Exception e) {
                        // TODO: handle exception
                    }
                } else {
                    try {
                        recording = true;
                        recorder.start();
                        button.setText("stop");

                    } catch (Exception e) {
                        // TODO: handle exception
                    }
                }
            }
        });
    }

    private void initRecorder() {
        try {
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
            // recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

            CamcorderProfile cpHigh = CamcorderProfile
                    .get(CamcorderProfile.QUALITY_HIGH);

            recorder.setProfile(cpHigh);
            recorder.setOutputFile("/sdcard/audiometer/video/"+str_getValue+"");
            recorder.setMaxDuration(1200000000); // 50 seconds
            recorder.setMaxFileSize(22000000); // Approximately 5 megabytes
        } catch (Exception e) {
            // TODO: handle exception
        }
    }

    private void prepareRecorder() {
        try {
            recorder.setPreviewDisplay(holder.getSurface());

            try {
                recorder.prepare();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } catch (IllegalStateException e) {
            e.printStackTrace();

        } catch (Exception e) {
            // TODO: handle exception
        }
    }

    public void onClick(View v) {
        /*
         * if (recording) { recorder.stop(); recorder.release(); recording =
         * false; Log.v(TAG, "Recording Stopped"); initRecorder();
         * prepareRecorder(); } else { recording = true; recorder.start(); }
         */
    }

    public void surfaceCreated(SurfaceHolder holder) {
        prepareRecorder();
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
    }

    public void surfaceDestroyed(SurfaceHolder holder) {

        finish(); 
    }
}

dont Forget to add Run time permission for write external storage

Community
  • 1
  • 1
Manohar
  • 22,116
  • 9
  • 108
  • 144
  • Thanks, but I do not understand, your asnwer not showing date and time. only record video source. – chohyunwook Jan 12 '17 at 05:45
  • You can get the current time using any one of these answers http://stackoverflow.com/questions/5369682/get-current-time-and-date-on-android . Then place a view over your video at desired location and display time on it – Manohar Jan 12 '17 at 05:57
  • I try this. when I before record button click camera preview screen, show current time. over video preview. but record file not showing current time. – chohyunwook Jan 12 '17 at 06:18
  • i have an idea but its not good practise, just switch on the camera place time over the view and do screen recording instead of video recording – Manohar Jan 12 '17 at 06:45