hint

来源:互联网 发布:php代码大全 编辑:程序博客网 时间:2024/05/16 12:24
Open Declarationandroid.media.MediaRecorder

A common case of using MediaRecorder to record audio works as follows:

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() step recorder.release(); // Now the object cannot be reused 

Applications may want to register for informational and error events in order to be informed of some internal update and possible runtime errors during recording. Registration for such events is done by setting the appropriate listeners (via calls (tosetOnInfoListener(OnInfoListener)setOnInfoListener and/orsetOnErrorListener(OnErrorListener)setOnErrorListener). In order to receive the respective callback associated with these listeners, applications are required to create MediaRecorder objects on threads with a Looper running (the main UI thread by default already has a Looper running).

Note: Currently, MediaRecorder does not work on the emulator.

Developer Guides

For more information about how to use MediaRecorder for recording video, read theCamera developer guide. For more information about how to use MediaRecorder for recording sound, read theAudio Capture developer guide.

Summary

原创粉丝点击