Document directory
- ① Use mediarecoder
- ② Use localsocket
- ③ Mediarecorder Problems
Http://www.cnblogs.com/skyseraph/archive/2012/03/31/2427593.html
0
This article is only a series of coherence. In fact, mediarecoder has been used in the previous series of blog posts. For details, see the previous Android series blog Android (19)
1 Overview
Use mediarecorder of Android to bind localsocket to the setoutputfile function.
2 knowledge points ① use mediarecoder
For more information, see [questions about Android] multi-media: mediarecorder
② Use localsocket
Send and receive data simultaneously on a mobile phone.
Http://api.apkbus.com/reference/android/net/LocalSocket.html
Http://api.apkbus.com/reference/android/net/LocalServerSocket.html
3 core source code ① surfaceview
See [streaming media] Android real-time video collection-camera preview collection
And
[Questions about Android] multi-media: mediarecorder enables a recorder
② Init localsocket
private void initLocalSocket() { receiver = new LocalSocket(); try { lss = new LocalServerSocket("H264"); receiver.connect(new LocalSocketAddress("H264")); receiver.setReceiveBufferSize(500000); receiver.setSendBufferSize(500000); sender = lss.accept(); sender.setReceiveBufferSize(500000); sender.setSendBufferSize(500000); } catch (IOException e1) { e1.printStackTrace(); Log.e("", "localSocket error:" + e1.getMessage()); } }
③ Mediarecorder Problems
Reference: [Android tutorial] multi-media: mediarecoder video recorder
Multi-media: mediarecorder implements a recorder
The initiativevideo core module is attached.
Private Boolean initializevideo () {try {log. I (TAG, "# initializevideo .... "); // 〇 state: initial instantiates the mediarecorder object if (msurfaceview = NULL) {log. E (TAG, "msurfaceview is null in initializevideo"); Return false;} If (mmediarecorder = NULL) mmediarecorder = new mediarecorder (); else mmediarecorder. reset (); // 〇 state: initial => initialized // set audio source as microphone, video source as camera // Specified before settings recording-parameters or encoders, called only before setoutputformat mmediarecorder. setvideosource (mediarecorder. videosource. camera); // mmediarecorder. setaudiosource (mediarecorder. audiosource. MIC); // 〇 state: initialized => performanceconfigured // set the Audio Encoding encoding output format // three_gpp: 3GP format, h263 video arm Audio Encoding // MPEG-4: MPEG4 media file format // raw_amr: Only audio is supported and the Audio Encoding must be amr_nb // amr_nb: // arm _ MB: // default: // 3GP or MP4 // optional string lvideofilefullpath; lvideofilefullpath = ". 3GP ";//. MP4 mmediarecorder. setoutputformat (mediarecorder. outputformat. three_gpp); // mmediarecorder. setoutputformat (mediarecorder. outputformat. mpeg_4); log. I (TAG, "Video: current container format:" + "3GP \ n"); // sets the encoding of audio/audio files: AAC/amr_nb/amr_m B/default // video: H.263, MP4-SP, or H. 264 mmediarecorder. setvideoencoder (mediarecorder. videoencoder. h264); // mmediarecorder. setvideoencoder (mediarecorder. videoencoder. h263); // mmediarecorder. setvideoencoder (mediarecorder. videoencoder. mpeg_4_sp); log. I (TAG, "Video: Current encoding format:" + "h264 \ n"); // audio: AMR-NB /// mmediarecorder. setaudioencoder (mediarecorder. audioencoder. amr_nb); // sets the video recording Resolution. It must be placed after the encoding and format. Otherwise, an error is returned. // mmediarecorder. setvideosize (176,144); mmediarecorder. setvideosize (320,240); // mmediarecorder. setvideosize (720,480); log. I (TAG, "Video: current video size:" + "320*240 \ n"); // sets the recorded video frame rate. It must be placed after the encoding and format. Otherwise, the error message "mmediarecorder" is returned. setvideoframerate (frame_rate); // preview mmediarecorder. setpreviewdisplay (msurfaceholder. getsurface (); // set the output file mode: directly local storage or localsocket remote output if (bifnativeorremote) // native {lvideofilefullpath = strrecvideofilepath + String. valueof (system. currenttimemillis () + lvideofilefullpath; mrecvideofile = new file (lvideofilefullpath); // mmediarecorder. setoutputfile (mrecvide Ofile. getabsolutepath (); mmediarecorder. setoutputfile (mrecvideofile. getpath (); // called after set ** source before prepare log. I (TAG, "Start write into file ~ ");} Else // remote {mmediarecorder. setoutputfile (sender. getfiledescriptor (); // set to output log. I (TAG," Start send into sender ~ ");} // Mmediarecorder. setmaxduration (0); // called after setoutputfile before prepare, if zero or negation, disables the limit mmediarecorder. setmaxfilesize (0); // called after setoutputfile before prepare, if zero or negation, disables the limit try {mmediarecorder. setoninfolistener (this); mmediarecorder. setonerrorlistener (this); // 〇 state: performanceconfigured => prepared mmediarecorder. prepare ();// 〇 state: Prepared => recording mmediarecorder. Start (); bifrecinprocess = true; log. I (TAG, "initializevideo start! ");} Catch (exception e) {releasemediarecorder (); finish (); E. printstacktrace ();} return true;} catch (exception e) {// todo: handle exception E. printstacktrace (); Return false ;}}