Use MediaRecorder to record video files Android emulator cannot record audio. Life cycle First, you need to grant two permissions through ActivityCompat.requestPermissions(): <uses-permission android:name=”android.permission.CAMERA” /> <uses-permission android:name=”android.permission.RECORD_AUDIO” /> <uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” /> The steps to record audio using MediaRecorder are usually as follows: MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); recorder.setOutputFile(PATH_NAME); recorder.prepare(); recorder.start(); […]
Tag: mediarecorder
Android simple example code for recording using MediaRecorder
MainActivity.java package com.example.soundrecord_demo; import java.io.IOException; import android.media.MediaRecorder; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity implements OnClickListener{ private Button btn1, btn2; private MediaRecorder record; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn1 = (Button) findViewById(R.id.button1); btn2 = (Button) findViewById(R.id.button2); btn1.setOnClickListener(this); btn2.setOnClickListener(this); } @Override public boolean […]
Android development MediaRecorder audio recording
Foreword The MediaRecorder class is a class provided by the Android sdk specifically for audio and video recording. Generally, the mobile phone microphone is used to collect audio and the camera is used to collect images. This class is a simple audio recording class. Recording audio is simple and easy, but the control of the […]
Android development MediaRecorder uses Camera2 to record video
Foreword This blog encountered some problems before. For example, when obtaining mMediaRecorder.getSurface();, it was honestly prompted that it was not initialized, resulting in an error. Then I personally don’t need Camera2 recording because of my business, so I haven’t looked into it further. But recently, a master (thank you Li Gong) pointed out that it […]
Android development MediaRecorder uses Camera1 to record video
Foreword MediaRecorder can achieve video recording without relying on the Camera API, but if you need to switch the camera/set the focus/select the resolution, etc., you need the Camera to participate in recording the video. This blog will introduce the use of Camera1 to achieve video recording. This blog is not here Repeat the introduction […]
Android MediaRecorder records camera video stream as MP4 file
Use the camera2 interface, the version number is 28. package com.example.camera01; import android.Manifest; import android. content. Context; import android.content.pm.PackageManager; import android.hardware.camera2.CameraAccessException; import android.hardware.camera2.CameraCaptureSession; import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CameraDevice; import android.hardware.camera2.CameraManager; import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.params.OutputConfiguration; import android.hardware.camera2.params.SessionConfiguration; import android.hardware.camera2.params.StreamConfigurationMap; import android.media.MediaRecorder; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.HandlerThread; import android.util.Log; import android.util.Size; import android.view.Surface; import android.view.View; […]
Realization example of recording function (MediaRecorder, AudioRecord)
An example of Android recording function implementation (MediaRecorder) – Tencent Cloud Developer Community – Tencent Cloud This article introduces the example code (MediaRecorder) for recording in Android, and shares it with you, as follows: Android provides two APIs for the implementation of recording: MediaRecorder and AudioRecord, each with its own advantages and disadvantages. 1. MediaRecorder […]
[Solved] android MediaRecorder start failed: -38 [turn]
This article is reproduced from: http://blog.csdn.net/fnuwfnh/article/details/46698509 Recently, I was learning about android recording, and found that the APP that runs normally on some mobile phones hangs on the Huawei tablet. The Logcat of eclipse shows MediaRecorder start failed: -38. I checked the information, the reason is that my APP uses multi-channel recording when encoding, and […]