0
我想在我的Android應用程序中錄製視頻,包括音頻。到目前爲止,我已經能夠使用本網站其他地方的代碼錄製視頻,但我一直無法包含任何音頻。我如何記錄兩者? 我正在使用的代碼(Xamarin C#)設置媒體記錄器如下。這有點粗糙,並準備好了。如何使用Android媒體播放器錄製視頻和音頻
private void InitRecorder(Surface surface)
{
// It is very important to unlock the camera before doing setCamera
// or it will results in a black preview
if (mCamera == null)
{
mCamera = Camera.Open();
mCamera.Unlock();
}
if (mMediaRecorder == null)
mMediaRecorder = new MediaRecorder();
mMediaRecorder.SetPreviewDisplay(surface);
mMediaRecorder.SetCamera(mCamera);
mMediaRecorder.SetVideoSource(VideoSource.Default);
mMediaRecorder.SetOutputFormat(OutputFormat.Mpeg4);
mMediaRecorder.SetVideoEncoder(VideoEncoder.H264);
mMediaRecorder.SetVideoEncodingBitRate(512 * 1000);
mMediaRecorder.SetVideoFrameRate(30);
mMediaRecorder.SetVideoSize(640, 480);
mMediaRecorder.SetOutputFile(VIDEO_PATH_NAME);
try
{
mMediaRecorder.Prepare();
}
catch (Exception ex)
{
// This is thrown if the previous calls are not called with the
// proper order
}
mInitSuccesful = true;
}
權限:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-feature android:name="android.hardware.camera.autofocus" />
謝謝!