0

I am facing an issue using the MediaRecorder in Android Xamarin. When I try to start or stop a record this exception is raised :

07-15 21:06:40.984 W/System.err(13609): java.lang.IllegalStateException
07-15 21:06:41.014 W/System.err(13609):     at android.media.MediaRecorder.start(Native Method)
07-15 21:06:41.014 W/System.err(13609):     at md51ef13e2ce92dda6cb40f015673d2b702.VideoAnswerActivity.n_BtnTakeVideo(Native Method)
07-15 21:06:41.014 W/System.err(13609):     at md51ef13e2ce92dda6cb40f015673d2b702.VideoAnswerActivity.BtnTakeVideo(VideoAnswerActivity.java:39)
07-15 21:06:41.014 W/System.err(13609):     at java.lang.reflect.Method.invokeNative(Native Method)
07-15 21:06:41.014 W/System.err(13609):     at java.lang.reflect.Method.invoke(Method.java:515)
07-15 21:06:41.024 W/System.err(13609):     at android.view.View$1.onClick(View.java:3955)
07-15 21:06:41.024 W/System.err(13609):     at android.view.View.performClick(View.java:4575)
07-15 21:06:41.024 W/System.err(13609):     at android.view.View$PerformClick.run(View.java:18578)
07-15 21:06:41.024 W/System.err(13609):     at android.os.Handler.handleCallback(Handler.java:733)
07-15 21:06:41.024 W/System.err(13609):     at android.os.Handler.dispatchMessage(Handler.java:95)
07-15 21:06:41.024 W/System.err(13609):     at android.os.Looper.loop(Looper.java:136)
07-15 21:06:41.024 W/System.err(13609):     at android.app.ActivityThread.main(ActivityThread.java:5127)
07-15 21:06:41.024 W/System.err(13609):     at java.lang.reflect.Method.invokeNative(Native Method)
07-15 21:06:41.024 W/System.err(13609):     at java.lang.reflect.Method.invoke(Method.java:515)
07-15 21:06:41.024 W/System.err(13609):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
07-15 21:06:41.024 W/System.err(13609):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
07-15 21:06:41.024 W/System.err(13609):     at dalvik.system.NativeStart.main(Native Method)

I just follow this Xamarin tutorial to record a video : https://developer.xamarin.com/recipes/android/media/video/record_video/

Here the code for the Start() :

                recording = true;
                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.SetMaxDuration(30000);
                recorder.SetOrientationHint(90);
                recorder.Prepare();
                try
                {
                    recorder.Start();
                }
                catch (IllegalStateException e)
                {
                    // TODO Auto-generated catch block
                    e.PrintStackTrace();
                }
OrcusZ
  • 3,555
  • 2
  • 31
  • 48

1 Answers1

2

Remove the .Reset from your code as that is restarting/resetting the MediaRecorder and you will have to re-initilize it over.

Restarts the MediaRecorder to its idle state. After calling this method, you will have to configure it again as if it had just been constructed.

Ref: https://developer.xamarin.com/api/member/Android.Media.MediaRecorder.Reset()/

enter image description here

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • Sorry, I didn't notice that I let it in the code, I just add it following some post in StackOverflow. With or Without I have the same issue. – OrcusZ Jul 15 '16 at 19:30
  • I remove the reset, and I removed some application ( saturated storage ), and it's working again now.... Question Do you know how to preview it in portrait instead of landscape when i am recording? – OrcusZ Jul 15 '16 at 19:34
  • @OrcusZ `Portrait`? You mean the entire app or just the `VideoView` widget? – SushiHangover Jul 15 '16 at 19:38
  • Only the videoWidget. Because my app work in only in portrait... So when I record I want to have the same display that i am recording... – OrcusZ Jul 15 '16 at 19:39
  • @OrcusZ Use Android.Hardware.Camera2 for api21+ based phones. The api is different of course but the end result is the same. https://developer.xamarin.com/api/namespace/Android.Hardware.Camera2/ – SushiHangover Jul 17 '16 at 06:35
  • OK, this morning i try again to record and... the java error comes again... So strange – OrcusZ Jul 17 '16 at 06:38
  • @OrcusZ Storage space issues? – SushiHangover Jul 17 '16 at 06:40
  • Seems not I delete some cotent and I have 700 MB available. I am looking for the file name/folder. And I delete the file if already exist. – OrcusZ Jul 17 '16 at 06:42