I've got the code below.  The one problem that I am running into is that a file 
is created called myoutputfile.mp4.  Unfortunately, the file has 0 bytes in it. 
 Is there something that I am doing that is not writing the file to the sd 
card?  Any other suggestions are welcome as well.

Wally

    [Activity (Label = "Record Video")]            
    public class RecordVideo : Activity, ISurfaceHolderCallback
    {
        MediaRecorder mediaRecorder;
        SurfaceView sv;
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView(Resource.Layout.RecordVideo);
            var btnStart = FindViewById<Button>(Resource.Id.StartVid);
            btnStart.Click += HandleBtnStartClick;
            var btnStop = FindViewById<Button>(Resource.Id.StopVid);
            btnStop.Click += HandleBtnStopClick;
            sv = FindViewById<SurfaceView>(Resource.Id.displayVid);
            
            var holder = sv.Holder;
            holder.AddCallback(this); 
            holder.SetType(Android.Views.SurfaceType.PushBuffers); 
            holder.SetFixedSize(400, 300);
        }

        void HandleBtnStopClick (object sender, EventArgs e)
        {
            mediaRecorder.Stop();
        }

        void HandleBtnStartClick(object sender, EventArgs e)
        {
            try
            {
                mediaRecorder.Start();
            }
            catch (System.Exception sysExc)
            {
                Android.Util.Log.Error("Record Video", sysExc.Message);
            }
        }

        #region ISurfaceHolderCallback implementation
        void ISurfaceHolderCallback.SurfaceChanged (ISurfaceHolder holder, int 
format, int width, int height)
        {
            
        }

        void ISurfaceHolderCallback.SurfaceCreated(ISurfaceHolder holder)
        {
            try
            {
                mediaRecorder = new MediaRecorder();
                // Configure the input sources
                mediaRecorder.SetAudioSource(Android.Media.AudioSource.Mic);
                mediaRecorder.SetVideoSource(Android.Media.VideoSource.Camera);
                // Set the output format 
                
mediaRecorder.SetOutputFormat(Android.Media.OutputFormat.Default);
                // Specify the audio and video encoding 
                
mediaRecorder.SetAudioEncoder(Android.Media.AudioEncoder.Default);
                
mediaRecorder.SetVideoEncoder(Android.Media.VideoEncoder.Default);
                // Specify the output file 
                mediaRecorder.SetOutputFile("/sdcard/myoutputfile.mp4");
                mediaRecorder.SetPreviewDisplay(holder.Surface);
                // Prepare to record 
                mediaRecorder.Prepare();
            }
            catch (System.Exception sysExc)
            {
                Android.Util.Log.Error("Record Video", sysExc.Message);
            }
        }

        void ISurfaceHolderCallback.SurfaceDestroyed (ISurfaceHolder holder)
        {
            mediaRecorder.Release();
        }
        #endregion
    }

                                          
_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to