Video recording of Android Development 1

Source: Internet
Author: User

Video recording of Android development(2011-10-18 17:47:46) reproduced
Tags: android video recording Surfaceview Category: 3GAndroid Learning Notes
To use the video recording feature, use the Mediarecorder class, and the Surfaceview buildPublic class Mainactivity extends Activity {Public static final String TAG = "mainactivity";@Overrideprotected void OnDestroy () {mediarecorder.release ();Super.ondestroy ();}private Surfaceview Surfaceview;private Button Btn_start;private Button btn_stop;private Mediarecorder Mediarecorder;private Boolean record;@OverridePublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);Setcontentview (r.layout.main);Mediarecorder = new Mediarecorder ();Surfaceview = (surfaceview) Findviewbyid (R.id.surfaceview);       This.surfaceView.getHolder (). SetType (surfaceholder.surface_type_push_buffers);This.surfaceView.getHolder (). Setfixedsize (320, 240);//Set ResolutionBtn_start = (Button) Findviewbyid (R.id.btn_start);btn_stop= (Button) Findviewbyid (r.id.btn_stop);Clicklistener Clicklistener = new Clicklistener ();Btn_start.setonclicklistener (clicklistener);Btn_stop.setonclicklistener (clicklistener);    }private Final class Clicklistener implements view.onclicklistener{Public void OnClick (View v) {if (! Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {Toast.maketext (mainactivity.this, "SD card does not exist or write protected!", 1). Show ();return;}try {switch (V.getid ()) {Case R.id.btn_start:Mediarecorder.reset ();Mediarecorder.setvideosource (MediaRecorder.VideoSource.CAMERA);//capture video from cameraMediarecorder.setaudiosource (MediaRecorder.AudioSource.MIC);Mediarecorder.setoutputformat (MediaRecorder.OutputFormat.THREE_GPP);mediarecorder.setvideosize (+);mediarecorder.setvideoframerate (3);//3 frames per secondMediarecorder.setvideoencoder (MediaRecorder.VideoEncoder.H263);//Set video encoding methodMediarecorder.setaudioencoder (MediaRecorder.AudioEncoder.AMR_NB);file Videofile = new file (Environment.getexternalstoragedirectory (), System.currenttimemillis () + ". 3gp");Mediarecorder.setoutputfile (Videofile.getabsolutepath ());Mediarecorder.setpreviewdisplay (Surfaceview.getholder (). Getsurface ());mediarecorder.prepare ();//Expected PreparationMediarecorder.start ();//Start Burningrecord = true;Break ;Case R.id.btn_stop:if (record) {mediarecorder.stop ();record = false;}Break ;}} catch (Exception e) {log.e (TAG, e.tostring ());}}       }     }

Video recording of Android Development 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.