Hi Wally, I ran the code and it works fine for me (On Google Nexus S). The one thing I'd question is the "RECORD_VIDEO" permission. It looks like you've just made that one up :) Not sure if removing it will make the saving of the video start to work though.
Hope this helps, ChrisNTR On Thu, Oct 13, 2011 at 3:27 PM, Wally McClure < theevilprogram...@hotmail.com> wrote: > I'm trying to record some video via M4A running on my htc evo 4g running > gingerbread. Everything seems to work fine until I turn off the recording > by pressing the stop button, which called the media record's .Stop method. > I end up with a zero length file. This makes me think that I need to > either: > > - Set a different permission. I have my permissions displayed below. > If there is something else that I need to add, please point me in the > correct direction. > - Add some command that will explicitly save the video to the output > file. I have included my code below, please let me know if there is > something I am missing. > > > Wally > > Manifest file: > <?xml version="1.0" encoding="utf-8"?> > <manifest xmlns:android="http://schemas.android.com/apk/res/android" > android:versionCode="1" android:versionName="1.0" > package="monoandroidrecordvideo.monoandroidrecordvideo" > android:installLocation="internalOnly"> > <application android:label="MonoAndroidRecordVideo"> > </application> > <uses-sdk android:minSdkVersion="8" /> > <uses-permission android:name="android.permission.RECORD_AUDIO" /> > <uses-permission android:name="android.permission.RECORD_VIDEO" /> > <uses-permission android:name="android.permission.CAMERA" /> > <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" > /> > </manifest> > > Code: > using System; > using System.Collections.Generic; > using System.Linq; > using System.Text; > > using Android.App; > using Android.Content; > using Android.OS; > using Android.Runtime; > using Android.Views; > using Android.Widget; > using Android.Media; > > namespace MonoAndroidRecordVideo > { > [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) > { > try > { > mediaRecorder.Stop(); > } > catch (System.Exception sysExc ) > { > Android.Util.Log.Error("Record Video", sysExc.Message); > } > } > > 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 > { > > //SetRequestedOrientation(Android.Content.PM.ScreenOrientation.Portrait); > mediaRecorder = new MediaRecorder(); > > //CamcorderProfile cp = > CamcorderProfile.Get(CamcorderQuality.High); > //mediaRecorder.SetProfile(cp); > > mediaRecorder.SetMaxFileSize(100000); > // 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 > Monodroid@lists.ximian.com > > UNSUBSCRIBE INFORMATION: > http://lists.ximian.com/mailman/listinfo/monodroid > > -- ChrisNTR Microsoft ASPInsider http://weblogs.asp.net/chrishardy http://twitter.com/chrisntr
_______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid