コード例 #1
0
        public void StartRecord(string filename)
        {
            if (recorder != null)
            {
                recorder.Reset();
            }
            else
            {
                recorder = new MediaRecorder();
            }
            mCamera.Lock();
            mCamera.Unlock();

            recorder.SetCamera(mCamera);
            recorder.SetVideoSource(VideoSource.Camera);
            recorder.SetAudioSource(AudioSource.Camcorder);

            try
            {
                //try for full hd
                recorder.SetProfile(CamcorderProfile.Get(CURRENTCAMERA, CamcorderQuality.Q1080p));
            }
            catch
            {
                try
                {
                    recorder.SetProfile(CamcorderProfile.Get(CURRENTCAMERA, CamcorderQuality.Q720p));
                }
                catch
                {
                    try
                    {
                        //if not hd, try for highest phone can give
                        recorder.SetProfile(CamcorderProfile.Get(CURRENTCAMERA, CamcorderQuality.High));
                    }
                    catch
                    {
                        //if not, then set to low
                        recorder.SetProfile(CamcorderProfile.Get(CURRENTCAMERA, CamcorderQuality.Q480p));
                    }
                }
            }

            //recorder.SetAudioEncoder(AudioEncoder.Aac);
            //recorder.SetVideoEncoder(VideoEncoder.H264);
            recorder.SetPreviewDisplay(mPreview.Holder.Surface);
            recorder.SetOutputFile(filename);
            recorder.SetMaxDuration(1000 * 60 * 5);

            try
            {
                recorder.Prepare();
                recorder.Start();
            }
            catch (Exception e)
            {
                OnError?.Invoke(e.ToString());
            }
        }
コード例 #2
0
 private void releaseMediaRecorder()
 {
     if (mediaRecorder != null)
     {
         mediaRecorder.Reset();
         mediaRecorder.Release();
         mediaRecorder = null;
         camera.Lock();
     }
 }
コード例 #3
0
        /// <summary>
        /// Create the camera and try to set auto focus with flash
        /// </summary>
        /// <param name="holder"></param>
		public void CreateCamera(ISurfaceHolder holder) {
			try
			{
				_camera = Camera.Open();
				Camera.Parameters p = _camera.GetParameters();
				p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg;
				p.JpegQuality = 100;
				hasAutoFocus = (p.SupportedFocusModes.Contains(Camera.Parameters.FocusModeAuto));
				if (hasAutoFocus)
				{
					p.FocusMode = Camera.Parameters.FocusModeAuto;
					focusReady = true;
				}
				else if (p.SupportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousPicture))
				{
					p.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
				}
				if (p.SupportedFlashModes.Contains(Camera.Parameters.FlashModeOn))
				{
					p.FlashMode = Camera.Parameters.FlashModeOn;
				}
				_camera.SetParameters(p);
				_camera.SetDisplayOrientation(90);
				_camera.SetPreviewCallback(this);
				_camera.Lock();
				_camera.SetPreviewDisplay(holder);
				_camera.StartPreview();
				if (hasAutoFocus)
				{
					Toast.MakeText(this, "Press screen to focus", ToastLength.Long).Show();
				}
			}
			catch (Exception e)
			{
			}
		}