Android multimedia recording
Procedure for recording audio:
1. Create a recording object
2. Specify the recording device (initialization status)
3. Set the bit rate of the recorded audio.
4. Set the encoding format of the recorded audio.
5. Set the location for storing the recorded audio
6. Prepare the recording (preparation status)
7. Start recording
8. Stop recording
9. release resources
Recording sound permission
Audio Recording status chart
Public class MediaRecorderTest extends Activity {private MediaRecorder recorder; private MediaPlayer player; @ Overrideprotected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); setContentView (R. layout. recorder); // 1. Create the recording object recorder = new MediaRecorder (); // 2. Specify the recording device (initial status) recorder. setAudioSource (MediaRecorder. audioSource. MIC); // 3. Set the recording audio bit rate reco. Rder. setOutputFormat (MediaRecorder. outputFormat. DEFAULT); // 4. Set the encoding format of the recorded audio recorder. setAudioEncoder (MediaRecorder. audioEncoder. DEFAULT); // set the location for recording audio streams (This specifies the root directory of the mobile phone sdcardand the file name is music.pdf) recorder. setOutputFile (Environment. getExternalStorageDirectory (). getAbsolutePath () + musicloud); try {// 6. Prepare the recording (preparation status) recorder. prepare ();} catch (IllegalStateException e) {// TODO Auto-generated catch blocke. printStackTrac E ();} catch (IOException e) {// TODO Auto-generated catch blocke. printStackTrace () ;}// play the audio file you just played, and create a playback audio object player = new MediaPlayer (); try {// set the audio file player to be played. setDataSource (Environment. getExternalStorageDirectory (). getAbsolutePath () +/musicloud); // prepare to play the audio (preparation status) player. prepare ();} catch (IllegalArgumentException e) {// TODO Auto-generated catch blocke. printStackTrace ();} catch (IllegalStateException E) {// TODO Auto-generated catch blocke. printStackTrace ();} catch (IOException e) {// TODO Auto-generated catch blocke. printStackTrace () ;}} public void start (View view) {recorder. start (); // 7. start recording Toast. makeText (this, recording, 0 ). show ();} public void stop (View view) {recorder. stop (); // 8. stop the recording Toast. makeText (this, ends the recording, and saves the recording file to sdcard ., 0 ). show (); recorder. release (); // 9. release resources} public void play (View view) {player. start (); // start playing the recorded audio }}