The Media Recorder
- Introduction
- You can record audio or video to a file in the filesystem.
- This is not the same as using the camera - it's a different API.
- See this Android web page.
- The MediaRecorder State Diagram
- The edges indicate legal transitions
- MediaRecorder for Audio
- Enable the microphone in the emulator's extended controls ...
- Add permission to the manifest
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
- Create a MediaRecorder object
- Set the audio source with setAudioSource, e.g., to
MediaRecorder.AudioSource.MIC
- Set the output format with setOutputFormat, e.g., to
MediaRecorder.OutputFormat.MPEG_4
- Set the encoder with setAudioEncoder, e.g., to
MediaRecorder.AudioEncoder.AMR_NB
- Set the output file with setOutputFile
- Store files in the standard place
- Add permission to the manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- Prepare with prepare
- Use start to start recording
- Use stop to stop recording
- Use release to release resources
- Example
MainActivity.java
activity_main.xml
styles.xml
strings.xml
AndroidManifest.xml
- MediaRecorder and SurfaceView for Video
- Set up a Camera2 as explained in
Media Camera
- When the suffering ends, I'll continue rewriting this section of notes.