Android Multimedia--6 Step Mediarecorder Recording

Source: Internet
Author: User

Mediarecorder is recording
To use the first view API, you can see the Mediarecorder life cycle

The API not only gives the life cycle diagram, but also the following examples

Mediarecorder Recorder = new Mediarecorder ();Recorder. Setaudiosource(Mediarecorder. Audiosource. MIC);Recorder. Setoutputformat(Mediarecorder. OutputFormat. Three_GPP);Recorder. Setaudioencoder(Mediarecorder. Audioencoder. AMR_NB);Recorder. Setoutputfile(path_name);Recorder. Prepare();Recorder. Start(); Recording is now started... recorder. Stop();Recorder. Reset(); You can reuse the object by going back to Setaudiosource () stepRecorder. Release();//Now the object cannot is reused

After viewing the API we can try to write one;
"1" Lap Interface: two buttons, one to play a stop
"2" Plus click events
"3" Do not forget to add permission

<uses-permission android:name="android.permission.RECORD_AUDIO"/><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

"4" Get mediarecorder and set parameters

Recorder=new Mediarecorder ();Audio Source Recorder. Setaudiosource(Mediarecorder. Audiosource. MIC);Set Output format recorder. Setoutputformat(Mediarecorder. OutputFormat. Three_GPP);Audio Encoding Recorder. Setaudioencoder(Mediarecorder. Audioencoder. AMR_NB);Settings are saved under SDcard named Myrecord. 3GP Recorder. Setoutputfile(Environment. getExternalStorageDirectory() +"/MYRECORD.3GP");

"5" Start recording

 recorder.prepare();                    recorder.start();

"6" Stop recording

 recorder.stop();                recorder.reset();                recorder.release();

That's what it's all about.

The following is the full source

 Public  class mainactivity extends Activity implements View. Onclicklistener {    PrivateButton Mbuttonstart;PrivateButton Mbuttonstop;PrivateMediarecorder Recorder;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);        Mbuttonstart= (Button) Findviewbyid (R.id.button_start);        mbuttonstop= (Button) Findviewbyid (r.id.button_stop); Mbuttonstop.setonclicklistener ( This); Mbuttonstart.setonclicklistener ( This); }@Override     Public void OnClick(View v) {Switch(V.getid ()) { CaseR.id.button_start:recorder=NewMediarecorder ();                Recorder.setaudiosource (MediaRecorder.AudioSource.MIC);                Recorder.setoutputformat (MediaRecorder.OutputFormat.THREE_GPP);                Recorder.setaudioencoder (MediaRecorder.AudioEncoder.AMR_NB); Recorder.setoutputfile (environment.getexternalstoragedirectory () +"/MYRECORD.3GP");Try{Recorder.prepare ();                Recorder.start (); }Catch(IOException e)                {E.printstacktrace (); } Break; CaseR.id.button_stop:recorder.stop ();                Recorder.reset (); Recorder.release (); Break;default: Break; }    }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Multimedia--6 Step Mediarecorder Recording

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.