public void SurfaceCreated(ISurfaceHolder holder)
        {
            var outputFile = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.ToString(),
                                                    "myvideooutputfile.mp4");
            if (!recording)
            {
                mediaRecorder = new MediaRecorder();
                //correctCamera();
                //if (camera != null)
                //    mediaRecorder.SetCamera(camera);

                mediaRecorder.SetAudioSource(AudioSource.Mic);
                mediaRecorder.SetVideoSource(VideoSource.Camera);
                mediaRecorder.SetOutputFormat(OutputFormat.ThreeGpp);
                mediaRecorder.SetAudioEncoder(AudioEncoder.Aac);
                mediaRecorder.SetVideoEncoder(VideoEncoder.Mpeg4Sp);

                if (System.IO.File.Exists(outputFile))
                    System.IO.File.Delete(outputFile);
                System.IO.File.Create(outputFile);

                CamcorderProfile camProf = CamcorderProfile.Get(CamcorderQuality.Low);
                fps = camProf.VideoFrameRate;

                mediaRecorder.SetOutputFile(outputFile);
                mediaRecorder.SetPreviewDisplay(holder.Surface);
                mediaRecorder.Prepare();
            } else
            {
                mediaPlayer.SetDisplay(holder);
                mediaPlayer.SetDataSource(outputFile);
                mediaPlayer.Prepared += new EventHandler(mediaPlayer_Prepared);
                mediaPlayer.PrepareAsync();
            }
        }
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			SetContentView (Resource.Layout.video);

			string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/test.mp4";

			var record = FindViewById<Button> (Resource.Id.Record);
			var stop = FindViewById<Button> (Resource.Id.Stop);
			var play = FindViewById<Button> (Resource.Id.Play);       
			var video = FindViewById<VideoView> (Resource.Id.SampleVideoView);

			record.Click += delegate {

				video.StopPlayback ();

				recorder = new MediaRecorder ();

				recorder.SetVideoSource (VideoSource.Camera); 
				recorder.SetAudioSource (AudioSource.Mic);              
				recorder.SetOutputFormat (OutputFormat.Default);
				recorder.SetVideoEncoder (VideoEncoder.Default); 
				recorder.SetAudioEncoder (AudioEncoder.Default);  
				recorder.SetOutputFile (path);       
				recorder.SetPreviewDisplay (video.Holder.Surface);         
				recorder.Prepare ();
				recorder.Start ();      
			};

			stop.Click += delegate {

				if (recorder != null) {
					recorder.Stop ();
					recorder.Release ();
				}
			};

			play.Click += delegate {

				var uri = Android.Net.Uri.Parse (path);        
				video.SetVideoURI (uri);
				video.Start ();   
			};
		}
示例#3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Memory);

            ImageButton record = FindViewById<ImageButton> (Resource.Id.vid);
            ImageButton btnNormalDialog = FindViewById<ImageButton> (Resource.Id.img);

            _imageView = FindViewById<ImageView> (Resource.Id.imgv);
            btnNormalDialog.Click += ButtonOnClick;

            mToolbar = FindViewById<SupportToolbar>(Resource.Id.toolbar);
            mDrawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
            mLeftDrawer = FindViewById<ListView>(Resource.Id.left_drawer);

            mLeftDrawer.Tag = 0;

            SetSupportActionBar(mToolbar);

            mLeftDataSet = new List<string>();
            mLeftDataSet.Add ("Left Item 1");
            mLeftDataSet.Add ("Left Item 2");
            mLeftAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, mLeftDataSet);
            mLeftDrawer.Adapter = mLeftAdapter;
            mDrawerToggle = new MyActionBarDrawerToggle(
                this,							//Host Activity
                mDrawerLayout,					//DrawerLayout
                Resource.String.openDrawer,		//Opened Message
                Resource.String.closeDrawer		//Closed Message
            );

            mDrawerLayout.SetDrawerListener(mDrawerToggle);
            SupportActionBar.SetHomeButtonEnabled(true);
            SupportActionBar.SetDisplayShowTitleEnabled(true);
            mDrawerToggle.SyncState();

            if (bundle != null)
            {
                if (bundle.GetString("DrawerState") == "Opened")
                {
                    SupportActionBar.SetTitle(Resource.String.openDrawer);
                }

                else
                {
                    SupportActionBar.SetTitle(Resource.String.closeDrawer);
                }
            }

            else
            {
                //This is the first the time the activity is ran
                SupportActionBar.SetTitle(Resource.String.closeDrawer);
            }

            VideoView video = FindViewById<VideoView> (Resource.Id.vidv);

            _button = FindViewById<ImageButton> (Resource.Id.mica);

            string path1 = Environment.ExternalStorageDirectory.AbsolutePath + "/test.mp4";

            _button.Click += delegate {

                if (count == 1) {

                    _recorder.SetAudioSource (AudioSource.Mic);
                    _recorder.SetOutputFormat (OutputFormat.ThreeGpp);
                    _recorder.SetAudioEncoder (AudioEncoder.AmrNb);
                    _recorder.SetOutputFile (path1);
                    _recorder.Prepare ();
                    _recorder.Start ();
                    Toast toast = Toast.MakeText (this , "Audio Recording", ToastLength.Short);
                    toast.Show ();
                    count ++;
                } else if (count == 2) {
                    _recorder.Stop();
                    _recorder.Release ();

                    count = 0;
                    Toast toast = Toast.MakeText (this , "Recording Stopped", ToastLength.Short);
                    toast.Show ();
                }
            };

            record.Click += delegate {
                video.StopPlayback ();
                if(c1 == 1)
                {
                    _recorder = new MediaRecorder ();
                    _recorder.SetVideoSource (VideoSource.Camera);
                    _recorder.SetAudioSource (AudioSource.Mic);
                    _recorder.SetOutputFormat (OutputFormat.Default);
                    _recorder.SetVideoEncoder (VideoEncoder.Default);
                    _recorder.SetAudioEncoder (AudioEncoder.Default);
                    _recorder.SetOutputFile (path1);
                    _recorder.SetPreviewDisplay (video.Holder.Surface);
                    _recorder.Prepare ();
                    _recorder.Start ();
                    c1++;
                }
                else if(c1 == 2){
                    if (_recorder != null)
                    {
                        _recorder.Stop ();
                        _recorder.Release ();
                        c1 = 0;
                    }
                }
            };
        }
示例#4
0
        public void SurfaceCreated(ISurfaceHolder holder)
        {
            mediaRecord = new MediaRecorder ();
            mediaRecord.SetAudioSource (AudioSource.Mic);
            mediaRecord.SetVideoSource (VideoSource.Camera);
            mediaRecord.SetOutputFormat (OutputFormat.Default);
            mediaRecord.SetAudioEncoder (AudioEncoder.Default);
            mediaRecord.SetVideoEncoder (VideoEncoder.Default);

            System.IO.File.Create (videoFilename);

            mediaRecord.SetOutputFile (videoFilename);
            mediaRecord.SetPreviewDisplay (holder.Surface);
            mediaRecord.Prepare ();
        }
示例#5
0
		//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;
			}
		}