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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:07:30+00:00 2026-05-24T09:07:30+00:00

I’m currently working on code written by someone else. I can see he implemented

  • 0

I’m currently working on code written by someone else. I can see he implemented the recorder layout as below

recorder = new MediaRecorder();
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);

mPreview = new Preview(VideoRecorder.this,recorder);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(mPreview);

My problem is I want to insert two Buttons into this mPreview programatically for record and stop.

How can I do that?

full class as below

public class VideoRecorder extends Activity {

    private SQLiteDatabase db;
    public ArrayList<String> videocount = new ArrayList<String>();

    public static int x = 1;

    public static boolean recod = false;
    public static boolean video = true;

    public boolean onCreateOptionsMenu(Menu menu) {

        // TODO Auto-generated method stub
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(a.b.R.menu.menus, menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        switch (item.getItemId()) {
        case id.record:

            if (video) {

                recorder.start();
                recod = true;
                video = false;
            } else {
                Toast.makeText(getApplicationContext(),
                        "Stop Recording First..", 2000).show();
            }

            break;
        case id.stop:
            if (recod) {

                String outputfilepath = "/sdcard/RdmsVideo" + x + ".3gpp";
                recorder.stop();
                recorder.release();
                recorder = null;
                video = true;
                this.db = this.openOrCreateDatabase("filestore", MODE_PRIVATE,
                        null);
                this.db.execSQL("CREATE TABLE IF NOT EXISTS videos(urls text)");
                db.execSQL("insert into videos values ('" + outputfilepath
                        + "')");
                db.close();
                x++;

                // Toast.makeText(getApplicationContext(), outputfilepath,
                // 2000).show();
                Intent i = new Intent(VideoRecorder.this, sendingpage.class);
                startActivity(i);
                this.finish();

            } else {
                Toast.makeText(getApplicationContext(), "Record First", 2000)
                        .show();
            }

            // Intent intent = getIntent();
            // finish();
            // startActivity(intent);
            break;

        }
        return true;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub

        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:

            homepage ff = new homepage();
            if (ff.vid == 1) {
                Intent i = new Intent(VideoRecorder.this, homepage.class);
                startActivity(i);
                this.finish();
            } else {
                Intent i = new Intent(VideoRecorder.this, tabpage.class);
                startActivity(i);
                this.finish();
            }

            break;

        default:
            break;
        }
        return super.onKeyDown(keyCode, event);
    }

    // Create objects of MediaRecorder and Preview class
    private MediaRecorder recorder;
    private Preview mPreview;

    boolean flag = false;
    boolean startedRecording = false;
    boolean stoppedRecording = false;

    // In this method, create an object of MediaRecorder class. Create an object
    // of
    // RecorderPreview class(Customized View). Add RecorderPreview class object
    // as content of UI.
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        recorder = new MediaRecorder();
        recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);

        mPreview = new Preview(VideoRecorder.this, recorder);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(mPreview);
        final LayoutParams lparams = new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        final Button record = new Button(VideoRecorder.this); // Activity goes
                                                                // here
        record.setText("Record");
        record.setLayoutParams(lparams);
        // record.setOnClickListener(...);
        //mPreview.add

    }

    /*
     * ! <p> Initialize the contents of the Activity's standard options menu.
     * Menu items are to be placed in to menu. This is called on each press of
     * menu button. In this options to start and stop recording are provided.
     * Option for start recording has group id 0 and option to stop recording is
     * 1. (first parameter of menu.add method). Start and stop have different
     * group id, if recording is already started then it shows stop option else
     * it shows start option. </p>
     */

    /*
     * ! <p> This method receives control when Item in menu option is selected.
     * It contains implementations to be performed on selection of menu item.
     * </p>
     */

    class Preview extends SurfaceView implements SurfaceHolder.Callback {
        // Create objects for MediaRecorder and SurfaceHolder.
        SurfaceHolder mHolder;
        MediaRecorder tempRecorder;

        // Create constructor of Preview Class. In this, get an object of
        // surfaceHolder class by calling getHolder() method. After that add
        // callback to the surfaceHolder. The callback will inform when surface
        // is
        // created/changed/destroyed. Also set surface not to have its own
        // buffers.
        public Preview(Context context, MediaRecorder recorder) {
            super(context);
            tempRecorder = recorder;
            mHolder = getHolder();
            mHolder.addCallback(this);
            mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

            // TODO Auto-generated constructor stub
        }

        public Surface getSurface() {
            return mHolder.getSurface();
        }

        // Implement the methods of SurfaceHolder.Callback interface

        // SurfaceCreated : This method gets called when surface is created.
        // In this, initialize all parameters of MediaRecorder object.
        // The output file will be stored in SD Card.

        public void surfaceCreated(SurfaceHolder holder) {

            tempRecorder.setOutputFile("/sdcard/RdmsVideo" + x + ".3gpp");
            tempRecorder.setPreviewDisplay(mHolder.getSurface());
            try {
                tempRecorder.prepare();
            } catch (Exception e) {
                String message = e.getMessage();
                tempRecorder.release();
                tempRecorder = null;
            }
        }

        public void surfaceDestroyed(SurfaceHolder holder) {
            if (tempRecorder != null) {
                tempRecorder.release();
                tempRecorder = null;
            }
        }

        public void surfaceChanged(SurfaceHolder holder, int format, int w,
                int h) {

        }
    }
}
  • 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-24T09:07:31+00:00Added an answer on May 24, 2026 at 9:07 am
    public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {        
    final LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        final Button record = new Button(this); //Activity goes here
        record.setText("Record");
        record.setLayoutParams(lparams);
        record.setOnClickListener(...);
        parent.addView(record);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.