Activity code:
650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:0px; "/>
package eoe.demo.media;import java.io.file;import java.io.ioexception;import android.app.activity;import android.media.mediarecorder;import android.os.bundle;import Android.os.environment;import android.view.surfaceholder;import android.view.surfaceview;import android.view.view;import android.view.view.onclicklistener;import android.widget.button;public class videoactivity extends activity {private file myrecaudiofile;private SurfaceView mSurfaceView;private SurfaceHolder mSurfaceHolder;private Button buttonstart;private button buttonstop;private file dir;private mediarecorder Recorder, @Overridepublic void oncreate (bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.video); msurfaceview = (Surfaceview) findviewbyid (R.id.videoview); msurfaceholder = Msurfaceview.getholder (); Msurfaceholder.settype (surfaceholder.surface_type_push_buffers); Buttonstart= (Button) Findviewbyid (R.id.start); buttonstop= (Button) Findviewbyid (r.id.stop); File defaultdir = environment.getexternalstoragedirectory (); String path = defaultdir.getabsolutepath () +file.separator+ "V" +file.separator;//Create folder to store video dir = new file (path); if (!dir.exists ()) {Dir.mkdir (); } recorder = new mediarecorder (); Buttonstart.setonclicklistener (New onclicklistener () {@Override Public void onclick (View  V) {recorder (); }}); Buttonstop.setonclicklistener (New onclicklistener () {@Override Public void onclick (View  V) {recorder.stop (); Recorder.reset (); Recorder.release (); Recorder=null; } });} Public void recorder () {try {myrecaudiofile = file.createtempfile ("video", ". 3gp", dir);//create temporary file Recorder.setpReviewdisplay (Msurfaceholder.getsurface ());//preview Recorder.setvideosource (MediaRecorder.VideoSource.CAMERA);//Video source Recorder.setaudiosource (MediaRecorder.AudioSource.MIC); //recording source is microphone Recorder.setoutputformat ( MediaRecorder.OutputFormat.THREE_GPP);//output format is 3gp recorder.setvideosize (800, 480);//Video size Recorder.setvideoframerate (15);//Video Frame Frequency recorder.setvideoencoder (MediaRecorder.VideoEncoder.H263);//Video encoding Recorder.setaudioencoder (MediaRecorder.AudioEncoder.AMR_NB);//Audio Codec recorder.setmaxduration (10000);//maximum duration Recorder.setoutputfile (Myrecaudiofile.getabsolutepath ());//save Path Recorder.prepare (); Recorder.start ();} catch (ioexception e) {e.printstacktrace (); } }}
650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:0px; "/>
Layout code:
650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:0px; "/>
<?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" > <surfaceview android: Id= "@+id/videoview" android:visibility= "visible" android:layout_ Width= "320px" android:layout_height= "240px" > </surfaceview > <RelativeLayout android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" > <Button android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" &nbSp android:text= "Recording" android:id= "@+id/start"/> < button android:layout_width= "Wrap_content" android:layout_height = "Wrap_content" android:layout_torightof= "@id/start" android: text= "Stop" android:id= "@+id/stop"/> </relativelayout> </LinearLayout>
650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:0px; "/>
Androidmanifest.xml:
650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:0px; "/>
<!--grant the program the right to record sound--<uses-permission android:name= "Android.permission.RECORD_AUDIO"/> <!--grant the program use Like head of authority--<uses-permission android:name= "Android.permission.CAMERA"/> <uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <!--grant permission to use external storage--<uses-permission android:name= "a Ndroid.permission.WRITE_EXTERNAL_STORAGE "/>
650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:0px; "/>
Android Recording Video