public void SetUpRecoder() { try { if (null == activity) { return; } if (userResponse == UserResponse.Video) { mediaRecorder = new MediaRecorder(); mediaRecorder.Reset(); mediaRecorder.SetAudioSource(AudioSource.Mic); mediaRecorder.SetVideoSource(VideoSource.Surface); mediaRecorder.SetOutputFormat(OutputFormat.Mpeg4); mediaRecorder.SetOutputFile(path + "/test.mp4"); mediaRecorder.SetVideoEncodingBitRate(10000000); mediaRecorder.SetVideoFrameRate(30); mediaRecorder.SetVideoSize(videoSize.Width, videoSize.Height); mediaRecorder.SetVideoEncoder(VideoEncoder.H264); mediaRecorder.SetAudioEncoder(AudioEncoder.Aac); //int rotation = (int)activity.WindowManager.DefaultDisplay.Rotation; //int orientation = ORIENTATIONS.Get(rotation); if (LensFacing == CameraFacing.BACK) { mediaRecorder.SetOrientationHint(90); } else { mediaRecorder.SetOrientationHint(270); } mediaRecorder.SetMaxDuration(30000); mediaRecorder.Prepare(); } else { mediaRecorder = new MediaRecorder(); mediaRecorder.Reset(); mediaRecorder.SetAudioSource(AudioSource.Mic); mediaRecorder.SetOutputFormat(OutputFormat.ThreeGpp); mediaRecorder.SetAudioEncoder(AudioEncoder.AmrNb); mediaRecorder.SetOutputFile(path + "/test.mp3"); mediaRecorder.SetMaxDuration(30000); mediaRecorder.Prepare(); } } catch (System.Exception ex) { } }
public void SetVideo() { var recorder = new Android.Media.MediaRecorder(); recorder.SetAudioSource(AudioSource.Mic); recorder.SetVideoSource(VideoSource.Surface); recorder.SetOutputFormat(OutputFormat.Mpeg4); recorder.SetVideoEncodingBitRate(10000000); recorder.SetVideoFrameRate(30); recorder.SetVideoEncoder(VideoEncoder.H264); recorder.SetAudioEncoder(AudioEncoder.Aac); recorder.SetVideoSize(_previewSize.Width, _previewSize.Height); SurfaceOrientation rotation = windowManager.DefaultDisplay.Rotation; recorder.SetOrientationHint(); var pfd = new ParcelFileDescriptor(ParcelFileDescriptor.FromSocket(new Socket())); recorder.SetOutputFile(pfd.FileDescriptor); #region sample /*mediaRecorder.SetAudioSource(AudioSource.Mic); * mediaRecorder.SetVideoSource(VideoSource.Surface); * mediaRecorder.SetOutputFormat(OutputFormat.Mpeg4); * mediaRecorder.SetOutputFile(GetVideoFile(Activity).AbsolutePath); * mediaRecorder.SetVideoEncodingBitRate(10000000); * mediaRecorder.SetVideoFrameRate(30); * mediaRecorder.SetVideoSize(videoSize.Width, videoSize.Height); * mediaRecorder.SetVideoEncoder(VideoEncoder.H264); * mediaRecorder.SetAudioEncoder(AudioEncoder.Aac); * int rotation = (int)Activity.WindowManager.DefaultDisplay.Rotation; * int orientation = ORIENTATIONS.Get(rotation); * mediaRecorder.SetOrientationHint(orientation); // * mediaRecorder.Prepare();*/ #endregion }
private void startRecordingVideo() { if (null == Activity) return; media_recorder = new MediaRecorder (); File file = getVideoFile (Activity); try { //UI button_video.SetText (Resource.String.stop); is_recording_video = true; //Configure the MediaRecorder media_recorder.SetAudioSource (AudioSource.Mic); media_recorder.SetVideoSource (VideoSource.Surface); media_recorder.SetOutputFormat (OutputFormat.Mpeg4); media_recorder.SetOutputFile (System.IO.Path.GetFullPath (file.ToString())); media_recorder.SetVideoEncodingBitRate (10000000); media_recorder.SetVideoFrameRate (30); media_recorder.SetVideoSize (1440, 1080); media_recorder.SetVideoEncoder (VideoEncoder.H264); media_recorder.SetAudioEncoder (AudioEncoder.Aac); int rotation = (int)Activity.WindowManager.DefaultDisplay.Rotation; int orientation = ORIENTATIONS.Get (rotation); media_recorder.SetOrientationHint (orientation); media_recorder.Prepare (); Surface surface = media_recorder.Surface; //Set up CaptureRequest builder = camera_device.CreateCaptureRequest (CameraTemplate.Record); builder.AddTarget (surface); var preview_surface = new Surface (texture_view.SurfaceTexture); builder.AddTarget (preview_surface); var surface_list = new List<Surface>(); surface_list.Add(surface); surface_list.Add(preview_surface); camera_device.CreateCaptureSession(surface_list,new RecordingCaptureStateListener(this),null); } catch (IOException e) { e.PrintStackTrace (); } catch (CameraAccessException e) { e.PrintStackTrace (); } catch (IllegalStateException e) { e.PrintStackTrace (); } }
//PREPARAMOS NUESTRO MEDIA RECORD Y CAMARA private bool PrepararVideoRecorder() { //OBTENEMOS LA INSTANCIA DE NUESTRA CAMARA YA PREPARADA _camera = ObtenerInstanciaCamara(); //INICIALIZAMOS NUESTRA VARIABLE MEDIARECORDER _mediaRecorder = new MediaRecorder(); //LE INDICAMOS A NUESTRA CAMARA QUE CAMBIE DE ROTACION ESTO ES DEVIDO QUE POR DEFUALT NOS MUESTRA EN POSICION HORIZONTAL, //Y COMO DEFINIMOS QUE LA POSICION DE NUESTRA APP SEA Portrait, REALIZAMOS EL CAMBIO. _camera.SetDisplayOrientation (90); //ABRIMOS NUESTRA CAMARA PARA SER USADA _camera.Unlock(); //DE IGUAL FORMA QUE NUESTRA CAMARA CAMBIAMOS LA POSICION DE NUESTRA MEDIARECORDER _mediaRecorder.SetOrientationHint (90); //ASIGNAMOS LA CAMARA A NUESTRA MEDIARECORDER _mediaRecorder.SetCamera(_camera); //ASIGNAMOS LOS FORMATOS DE VIDEO Y AUDIO _mediaRecorder.SetAudioSource(AudioSource.Camcorder); _mediaRecorder.SetVideoSource(VideoSource.Camera); //RECUPERAMOS EL PERFIL QUE TIENE NUESTRA CAMARA PARA PODER ASIGNARSELA A NUESTRA MEDIARECORDER var camcorderProfile = ((int)Build.VERSION.SdkInt) >= 9 ? CamcorderProfile.Get(0, CamcorderQuality.High) : CamcorderProfile.Get(CamcorderQuality.High); //ASIGNAMOS EL PERFIL A NUESTRO MEDIARECORDER _mediaRecorder.SetProfile(camcorderProfile); //LE ASIGNAMOS EL PATH DONDE SE ENCUESTRA NUESTRO ARCHIVO DE VIDEO PARA PODER CREARLO _mediaRecorder.SetOutputFile(PathArchivoVideo ()); //ASIGNAMOS EL SURFACE A NUESTRO MEDIARECORDER QUE UTILIZARA PARA VISUALIZAR LO QUE ESTAMOS GRABANDO _mediaRecorder.SetPreviewDisplay(_videoView.Holder.Surface); try { //CONFIRMAMOS LOS CAMBIOS HECHOS EN NUESTRO MEDIA RECORDER PARA PODER INICIAR A GRABAR _mediaRecorder.Prepare(); return true; } catch { //SI OCURRE ALGUN PROBLEMA LIBRAMOS LOS RECURSOS ASIGNADOS A NUESTRO MEDIARECORDER LiberarMediaRecorder(); return false; } }