Error on VideoRecorder sample

I'm testing around the video recorder sample from xamarin knowledge base: http://docs.xamarin.com/recipes/android/media/video/record_video

the variable
Path = /mnt/sdcard/test.mp4

Debugger:

[MediaRecorderJNI] prepare: surface=0x4b10eb40 (identity=163)
[MediaRecorder] start failed: -19
Java.Lang.RuntimeException: Exception of type 'Java.Lang.RuntimeException' was thrown.
at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod) [0x00022] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:356
at Android.Media.MediaRecorder.Start () [0x0003e] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.Media.MediaRecorder.cs:1192
at chatterbox.mRecorder+c__AnonStorey2.<>m__8 (System.Object , System.EventArgs ) [0x000b6] in /Users/utente/Xamarin-Projects/Doxa/chatterbox/Recorder.cs:48
--- End of managed exception stack trace ---
java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.start(Native Method)
at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
at android.view.View.performClick(View.java:4202)
at android.view.View$PerformClick.run(View.java:17340)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)

Can't understand where is the issue.
Please help.
Thanks,
Max.

«1

Posts

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭
    edited May 2013

    Are you running this on the device? (emulator might not work)

    I also think WRITE_EXTERNAL_STORAGE permission should be added.

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    It's the first thing I've done ;)
    not there the problem .... any other idea ?

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    The test.mp4 file is created at 0 bytes

  • StevenTheEvenStevenTheEven SEMember ✭✭✭

    And if you save it on your device and not external storage it works or not?

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Could you attach the Android Debug Log?

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭
    edited May 2013

    I/ActivityManager( 345): START u0 {cmp=com.doxa.map/chatterbox.mRecorder} from pid 3231 V/AudioPolicyManagerBase( 86): getOutput() stream 1, samplingRate 0, format 0, channelMask 3, flags 0 V/AudioPolicyManagerBase( 86): getOutput() returns output 2 V/AudioPolicyManagerBase( 86): getOutput() stream 1, samplingRate 0, format 0, channelMask 3, flags 0 V/AudioPolicyManagerBase( 86): getOutput() returns output 2 V/AudioPolicyManagerBase( 86): getOutput() stream 1, samplingRate 44100, format 1, channelMask 1, flags 4 V/AudioPolicyManagerBase( 86): getOutput() returns output 2 V/AudioPolicyManagerBase( 86): startOutput() output 2, stream 1, session 24 V/AudioPolicyManagerBase( 86): changeRefCount() stream 1, count 1 V/AudioPolicyManagerBase( 86): getNewDevice() selected device 2 V/AudioPolicyManagerBase( 86): setOutputDevice() output 2 device 0002 delayMs 0 V/AudioPolicyManagerBase( 86): setOutputDevice() prevDevice 0002 V/AudioPolicyManagerBase( 86): setOutputDevice() setting same device 0002 or null device for output 2 D/audio_hw_primary( 86): start_output_stream: card:0, port:0, rate:44100 V/alsa_pcm( 86): pcm_open_req, playback card: 0, device: 0, req_rate: 44100 V/alsa_pcm( 86): pcm_open_req try rate: 44100 V/alsa_pcm( 86): pcm_open_req OK config->rate: 44100 V/AudioPolicyManagerBase( 86): releaseOutput() 2 V/AudioPolicyManagerBase( 86): stopOutput() output 2, stream 1, session 24 V/AudioPolicyManagerBase( 86): changeRefCount() stream 1, count 0 V/AudioPolicyManagerBase( 86): getNewDevice() selected device 0 V/AudioPolicyManagerBase( 86): setOutputDevice() output 2 device 0000 delayMs 190 V/AudioPolicyManagerBase( 86): setOutputDevice() prevDevice 0002 V/AudioPolicyManagerBase( 86): setOutputDevice() setting same device 0000 or null device for output 2 I/mono-stdout( 3231): /mnt/sdcard/test.mp4 E/SurfaceFlinger( 320): ro.sf.lcd_density must be defined as a build property I/SurfaceFlinger( 320): GraphicBufferAlloc::createGraphicBuffer E/SurfaceFlinger( 320): ro.sf.lcd_density must be defined as a build property I/ActivityManager( 345): Displayed com.doxa.map/chatterbox.mRecorder: +448ms I/SurfaceFlinger( 320): GraphicBufferAlloc::createGraphicBuffer I/SurfaceFlinger( 320): GraphicBufferAlloc::createGraphicBuffer V/AudioPolicyManagerBase( 86): getOutput() stream 1, samplingRate 0, format 0, channelMask 3, flags 0 V/AudioPolicyManagerBase( 86): getOutput() returns output 2 V/AudioPolicyManagerBase( 86): getOutput() stream 1, samplingRate 0, format 0, channelMask 3, flags 0 V/AudioPolicyManagerBase( 86): getOutput() returns output 2 V/AudioPolicyManagerBase( 86): getOutput() stream 1, samplingRate 44100, format 1, channelMask 1, flags 4 V/AudioPolicyManagerBase( 86): getOutput() returns output 2 V/AudioPolicyManagerBase( 86): startOutput() output 2, stream 1, session 25 V/AudioPolicyManagerBase( 86): changeRefCount() stream 1, count 1 V/AudioPolicyManagerBase( 86): getNewDevice() selected device 2 V/AudioPolicyManagerBase( 86): setOutputDevice() output 2 device 0002 delayMs 0 V/AudioPolicyManagerBase( 86): setOutputDevice() prevDevice 0002 V/AudioPolicyManagerBase( 86): setOutputDevice() setting same device 0002 or null device for output 2 V/AudioPolicyManagerBase( 86): releaseOutput() 2 D/CedarXRecorder( 86): Calling process is: com.doxa.map ! V/AudioPolicyManagerBase( 86): stopOutput() output 2, stream 1, session 25 V/AudioPolicyManagerBase( 86): changeRefCount() stream 1, count 0 V/AudioPolicyManagerBase( 86): getNewDevice() selected device 0 V/AudioPolicyManagerBase( 86): setOutputDevice() output 2 device 0000 delayMs 190 V/AudioPolicyManagerBase( 86): setOutputDevice() prevDevice 0002 V/AudioPolicyManagerBase( 86): setOutputDevice() setting same device 0000 or null device for output 2 I/MediaRecorderJNI( 3231): prepare: surface=0x4aeb7c00 (identity=36) E/SurfaceFlinger( 320): ro.sf.lcd_density must be defined as a build property E/MediaProfiles( 86): The given video encoder 1 is not found E/MediaProfiles( 86): The given video encoder 1 is not found E/MediaProfiles( 86): The given video encoder 1 is not found E/MediaProfiles( 86): The given video encoder 1 is not found E/MediaProfiles( 86): The given video encoder 1 is not found E/MediaProfiles( 86): The given video encoder 1 is not found E/MediaProfiles( 86): The given video encoder 1 is not found E/MediaProfiles( 86): The given video encoder 1 is not found D/CameraHardware( 86): Calling process is: /system/bin/mediaserver I/AwesomePlayer( 86): setDataSource_l(URL suppressed) I/AwesomePlayer( 86): setDataSource_l(URL suppressed) I/CameraClient( 86): Opening camera 0 D/CameraHardware( 86): Calling process is: /system/bin/mediaserver D/osal_linux( 86): init hw ref count:1 D/CameraSource( 86): Camera does not support setVideoSize() E/CameraSource( 86): Video dimension (176x144) is unsupported D/osal_linux( 86): exit hw ref count:0 D/V4L2CameraDevice( 86): cedarx_hardware_exit ok I/CameraClient( 86): Destroying camera 0 E/MediaRecorder( 3231): start failed: -19 I/mono-stdout( 3231): Java.Lang.RuntimeException: Exception of type 'Java.Lang.RuntimeException' was thrown. I/mono-stdout( 3231): at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod) [0x00000] in <filename unknown>:0 I/mono-stdout( 3231): at Android.Media.MediaRecorder.Start () [0x00000] in <filename unknown>:0 I/mono-stdout( 3231): at chatterbox.mRecorder+<OnCreate>c__AnonStorey2.<>m__9 (System.Object , System.EventArgs ) [0x00000] in <filename unknown>:0 I/mono-stdout( 3231): --- End of managed exception stack trace --- I/mono-stdout( 3231): java.lang.RuntimeException: start failed. I/mono-stdout( 3231): at android.media.MediaRecorder.start(Native Method) I/mono-stdout( 3231): at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method) I/mono-stdout( 3231): at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29) I/mono-stdout( 3231): at android.view.View.performClick(View.java:4202) I/mono-stdout( 3231): at android.view.View$PerformClick.run(View.java:17340) I/mono-stdout( 3231): at android.os.Handler.handleCallback(Handler.java:725) I/mono-stdout( 3231): at android.os.Handler.dispatchMessage(Handler.java:92) I/mono-stdout( 3231): at android.os.Looper.loop(Looper.java:137) I/mono-stdout( 3231): at android.app.ActivityThread.main(ActivityThread.java:5039) I/mono-stdout( 3231): at java.lang.reflect.Method.invokeNative(Native Method) I/mono-stdout( 3231): at java.lang.reflect.Method.invoke(Method.java:511) I/mono-stdout( 3231): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) I/mono-stdout( 3231): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) I/mono-stdout( 3231): at dalvik.system.NativeStart.main(Native Method)

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    The given video encoder 1 is not found stands out. Also Camera does not support setVideoSize() E/CameraSource( 86): Video dimension (176x144) is unsupported.

    You may want to start there.

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    Commented out but continues to crash
    (setVideoSize not used)

    try { 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 (); }catch(Exception exc) { Console.WriteLine(exc.ToString()); }

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    No, I think you will need to try looking for an encoder that works for your device. Using the default or commenting out might not be giving you a valid encoder. Similar for the display size.

    Camera access is a bit of a nightmare on Android, due to device fragmentation.

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    There's a way to detect the device encoder or to find a workaround about display size ?
    THanks in advance
    Max

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Yes.

    You may also want to experiment with CamcorderProfile:
    http://stackoverflow.com/questions/13596659/android-mediarecorder-start-failed-12

    Incidentally, if all you want to do is simply capture some video, and you do not have very specific needs beyond that, it's much easier to use the standard MediaStore.ACTION_VIDEO_CAPTURE intent instead. That's plug-and-play.

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    I have followed the Android guidelines to capture video:
    http://developer.android.com/guide/topics/media/camera.html#capture-video
    Until I do start all works fine. When I click on record button to start I have this error:
    D/dalvikvm( 1019): GC_CONCURRENT freed 368K, 8% free 4940K/5336K, paused 2ms+7ms, total 49ms I/SurfaceFlinger( 320): GraphicBufferAlloc::createGraphicBuffer E/MediaProfiles(13173): The given video encoder 1 is not found E/MediaProfiles(13173): The given video encoder 1 is not found E/MediaProfiles(13173): The given video encoder 1 is not found E/MediaProfiles(13173): The given video encoder 1 is not found E/MediaProfiles(13173): The given video encoder 1 is not found E/MediaProfiles(13173): The given video encoder 1 is not found E/MediaProfiles(13173): The given video encoder 1 is not found E/MediaProfiles(13173): The given video encoder 1 is not found D/CameraSource(13173): Camera does not support setVideoSize() E/CameraSource(13173): Video dimension (176x144) is unsupported V/AudioPolicyManagerBase(13173): getOutput() stream 1, samplingRate 0, format 0, channelMask 3, flags 0 V/AudioPolicyManagerBase(13173): getOutput() returns output 2 V/AudioPolicyManagerBase(13173): getOutput() stream 1, samplingRate 0, format 0, channelMask 3, flags 0 V/AudioPolicyManagerBase(13173): getOutput() returns output 2 V/AudioPolicyManagerBase(13173): getOutput() stream 1, samplingRate 44100, format 1, channelMask 1, flags 4 V/AudioPolicyManagerBase(13173): getOutput() returns output 2 V/AudioPolicyManagerBase(13173): startOutput() output 2, stream 1, session 291 V/AudioPolicyManagerBase(13173): changeRefCount() stream 1, count 1 V/AudioPolicyManagerBase(13173): getNewDevice() selected device 2 V/AudioPolicyManagerBase(13173): setOutputDevice() output 2 device 0002 delayMs 0 V/AudioPolicyManagerBase(13173): setOutputDevice() prevDevice 0002 V/AudioPolicyManagerBase(13173): setOutputDevice() setting same device 0002 or null device for output 2 D/audio_hw_primary(13173): start_output_stream: card:0, port:0, rate:44100 V/alsa_pcm(13173): pcm_open_req, playback card: 0, device: 0, req_rate: 44100 V/alsa_pcm(13173): pcm_open_req try rate: 44100 V/alsa_pcm(13173): pcm_open_req OK config->rate: 44100 V/AudioPolicyManagerBase(13173): releaseOutput() 2 E/MediaRecorder(28405): start failed: -19 V/AudioPolicyManagerBase(13173): stopOutput() output 2, stream 1, session 291 V/AudioPolicyManagerBase(13173): changeRefCount() stream 1, count 0 V/AudioPolicyManagerBase(13173): getNewDevice() selected device 0 V/AudioPolicyManagerBase(13173): setOutputDevice() output 2 device 0000 delayMs 190 V/AudioPolicyManagerBase(13173): setOutputDevice() prevDevice 0002 V/AudioPolicyManagerBase(13173): setOutputDevice() setting same device 0000 or null device for output 2 I/mono-stdout(28405): Java.Lang.RuntimeException: Exception of type 'Java.Lang.RuntimeException' was thrown. I/mono-stdout(28405): at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod) [0x00000] in <filename unknown>:0 I/mono-stdout(28405): at Android.Media.MediaRecorder.Start () [0x00000] in <filename unknown>:0 I/mono-stdout(28405): at chatterbox.mRecorder.<OnCreate>m__9 (System.Object , System.EventArgs ) [0x00000] in <filename unknown>:0 I/mono-stdout(28405): --- End of managed exception stack trace --- I/mono-stdout(28405): java.lang.RuntimeException: start failed. I/mono-stdout(28405): at android.media.MediaRecorder.start(Native Method) I/mono-stdout(28405): at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method) I/mono-stdout(28405): at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29) I/mono-stdout(28405): at android.view.View.performClick(View.java:4202) I/mono-stdout(28405): at android.view.View$PerformClick.run(View.java:17340) I/mono-stdout(28405): at android.os.Handler.handleCallback(Handler.java:725) I/mono-stdout(28405): at android.os.Handler.dispatchMessage(Handler.java:92) I/mono-stdout(28405): at android.os.Looper.loop(Looper.java:137) I/mono-stdout(28405): at android.app.ActivityThread.main(ActivityThread.java:5039) I/mono-stdout(28405): at java.lang.reflect.Method.invokeNative(Native Method) I/mono-stdout(28405): at java.lang.reflect.Method.invoke(Method.java:511) I/mono-stdout(28405): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) I/mono-stdout(28405): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) I/mono-stdout(28405): at dalvik.system.NativeStart.main(Native Method) I/SurfaceFlinger( 320): GraphicBufferAlloc::createGraphicBuffer D/dalvikvm( 595): GC_CONCURRENT freed 511K, 10% free 5954K/6560K, paused 7ms+4ms, total 62ms

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Thanks for pointing out the Android guidelines document, that was actually really helpful.

    I have whipped up some quick Xamarin.Android code based on that, and it works fine on the device - the video is displayed and recorded, and the resulting .mp4 looks and works fine. Note that it does NOT work on the emulator. I do not think the emulator supports direct Camera access.

    Code sample (just paste in your activity):

    [Activity (Label = "RecordVideo", MainLauncher = true)]
    public class Activity1 : Activity
    {
        MediaRecorder _mediaRecorder;
        Camera _camera;
        private VideoView _videoView;
    
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.Main);
    
            var recordButton = FindViewById<Button> (Resource.Id.Record);
            var stopButton = FindViewById<Button> (Resource.Id.Stop);     
            _videoView = FindViewById<VideoView> (Resource.Id.SampleVideoView);
    
            recordButton.Click += delegate
            {
                if (PrepareVideoRecorder())
                {
                    _mediaRecorder.Start();
                }
                else
                {
                    ReleaseMediaRecorder();
                }
            };
    
            stopButton.Click += delegate 
            {
                _mediaRecorder.Stop();
                ReleaseMediaRecorder();
                _camera.Lock();
            };
        }
    
        public static Camera GetCameraInstance()
        {
            try
            {
                return Camera.Open(); // attempt to get a Camera instance
            }
            catch
            {
                return null; // Camera is not available (in use or does not exist)
            }
        }
    
        private static string GetOutputMediaFilePath()
        {
            var mediaStorageDir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "SampleCameraApp");
            if (!mediaStorageDir.Exists())
            {
                if (!mediaStorageDir.Mkdirs()) return null;
            }
            return Path.Combine(mediaStorageDir.Path, String.Format("VID_{0}.mp4", Guid.NewGuid()));
        }
    
        private bool PrepareVideoRecorder()
        {
            _camera = GetCameraInstance();
            _mediaRecorder = new MediaRecorder();
    
            _camera.Unlock();
            _mediaRecorder.SetCamera(_camera);
            _mediaRecorder.SetAudioSource(AudioSource.Camcorder);
            _mediaRecorder.SetVideoSource(VideoSource.Camera);
            _mediaRecorder.SetProfile(CamcorderProfile.Get(CamcorderQuality.High)); // requires API Level 8 or higher
            _mediaRecorder.SetOutputFile(GetOutputMediaFilePath());
            _mediaRecorder.SetPreviewDisplay(_videoView.Holder.Surface);
            try
            {
                _mediaRecorder.Prepare();
                return true;
            }
            catch
            {
                ReleaseMediaRecorder();
                return false;
            }
        }
    
        private void ReleaseCamera()
        {
            if (_camera == null) return;
            _camera.Release(); // release the camera for other applications, VERY important!!!
            _camera.Dispose();
            _camera = null;
        }
    
        private void ReleaseMediaRecorder()
        {
            if (_mediaRecorder == null) return;
            _mediaRecorder.Reset();
            _mediaRecorder.Release();
            _mediaRecorder.Dispose();
            _mediaRecorder = null;
            _camera.Lock();
        }
    
        protected override void OnDestroy ()
        {
            base.OnDestroy ();
            ReleaseMediaRecorder();
            ReleaseCamera();
        }
    }
    
  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Full project attached as well. I did not add a Play function, so that button does not do anything yet.

    The Android docs point out that the configuration steps need to happen in a specific order, and that we should be using CamcorderProfile (at least for Android 2.2+, but let's stay sane and take that as the baseline). Likely both of these things had to do with the issues you were seeing. Without CamcorderProfile, Android might have difficulty locating a valid encoder, etc.

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    Thanks Chris I'm going through to try.
    I will put feedback here

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    Sorry Chris but It doesn't work for me. I got an error :

    at this line:

    _camera = GetCameraInstance();
    _mediaRecorder = new MediaRecorder();

            _camera.Unlock();   <------- this object is null
    

    System.NullReferenceException: Object reference not set to an instance of an object
    at RecordVideo.Activity1.PrepareVideoRecorder () [0x00016] in /Users/utente/Downloads/RecordVideo(1)/RecordVideo/Activity1.cs:77
    at RecordVideo.Activity1.m__0 (object,System.EventArgs) [0x00000] in /Users/utente/Downloads/RecordVideo(1)/RecordVideo/Activity1.cs:32
    at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000b] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.Views.View.cs:950
    at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.Views.View.cs:921
    at at (wrapper dynamic-method) object.db1f3b7d-f762-442d-bc09-a58fe47911a6 (intptr,intptr,intptr)
    at

    I fixed this with: Camera.Open(0) .... but I'm mine project I can't use because
    debugger stops me tell me I can't use the Camera.Open(Int) ?????

    Then Now I have a break here:

    _mediaRecorder.SetProfile (CamcorderProfile.Get(CamcorderQuality.Low)); //requires API Level 8 or higher

    I changed to CamcorderQuality.Low but It's the same.

    Java.Lang.NullPointerException:
    at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00023] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:368
    at Android.Media.MediaRecorder.SetProfile (Android.Media.CamcorderProfile) [0x0003e] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.Media.MediaRecorder.cs:1016
    at RecordVideo.Activity1.PrepareVideoRecorder () [0x0004a] in /Users/utente/Downloads/RecordVideo(1)/RecordVideo/Activity1.cs:81
    at RecordVideo.Activity1.m__0 (object,System.EventArgs) [0x00000] in /Users/utente/Downloads/RecordVideo(1)/RecordVideo/Activity1.cs:32
    at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000b] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.Views.View.cs:950
    at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.Views.View.cs:921
    at at (wrapper dynamic-method) object.1736d863-d851-489d-91be-1a6ef672114c (intptr,intptr,intptr)
    at
    at --- End of managed exception stack trace ---
    at java.lang.NullPointerException
    at at android.media.MediaRecorder.setProfile(MediaRecorder.java:330)
    at at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
    at at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
    at at android.view.View.performClick(View.java:4202)
    at at android.view.View$PerformClick.run(View.java:17340)
    at at android.os.Handler.handleCallback(Handler.java:725)
    at at android.os.Handler.dispatchMessage(Handler.java:92)
    at at android.os.Looper.loop(Looper.java:137)
    at at android.app.ActivityThread.main(ActivityThread.java:5039)
    at at java.lang.reflect.Method.invokeNative(Native Method)
    at at java.lang.reflect.Method.invoke(Method.java:511)
    at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at at dalvik.system.NativeStart.main(Native Method)
    at

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Are you using the complete example project I attached?

    What is the device that you are testing with (and what version of Android is it running)?

    The Android docs say about Camera.Open():

    If the device does not have a back-facing camera, this returns null.

    Do you have a back-facing camera? What does Camera.NumberOfCameras return?

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    No the device is a DEVo tablet 7" and got onli one front-face camera

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    SO Camera.NumberOfCameras return 1

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Ok, but what Android version?

    And if you do not have a back-facing camera, you should indeed use Camera.Open(0). What kind of exception are you getting from that?

    Also, have you tried a complete reboot of the device? It says in the docs that if your app (or any other) fails to release the camera properly, you may run into difficulties:

    If your application does not properly release the camera, all subsequent attempts to access the camera, including those by your own application, will fail and may cause your or other applications to be shut down.

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    I bypassed the issue with:
    _mediaRecorder.SetOutputFormat (OutputFormat.Default);
    _mediaRecorder.SetVideoEncoder (VideoEncoder.Default);
    _mediaRecorder.SetAudioEncoder (AudioEncoder.Default);
    instead of:

    _mediaRecorder.SetProfile (CamcorderProfile.Get(CamcorderQuality.Low)); //requires API Level 8 or higher

    but on _mediarecorder.Start(); I have always the same issue ....

    Java.Lang.RuntimeException: start failed.
    at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr) [0x00022] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:356
    at Android.Media.MediaRecorder.Start () [0x0003e] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.Media.MediaRecorder.cs:1192
    at RecordVideo.Activity1.m__0 (object,System.EventArgs) [0x0000b] in /Users/utente/Downloads/RecordVideo(1)/RecordVideo/Activity1.cs:34
    at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000b] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.Views.View.cs:950
    at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.Views.View.cs:921
    at at (wrapper dynamic-method) object.6b0886ac-8825-4f4c-8bdc-ef1ee3b8d353 (intptr,intptr,intptr)
    at
    at --- End of managed exception stack trace ---
    at java.lang.RuntimeException: start failed.
    at at android.media.MediaRecorder.start(Native Method)
    at at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
    at at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
    at at android.view.View.performClick(View.java:4202)
    at at android.view.View$PerformClick.run(View.java:17340)
    at at android.os.Handler.handleCallback(Handler.java:725)
    at at android.os.Handler.dispatchMessage(Handler.java:92)
    at at android.os.Looper.loop(Looper.java:137)
    at at android.app.ActivityThread.main(ActivityThread.java:5039)
    at at java.lang.reflect.Method.invokeNative(Native Method)
    at at java.lang.reflect.Method.invoke(Method.java:511)
    at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at at dalvik.system.NativeStart.main(Native Method)
    at

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    By the way, just tried it on my device (Yarvik Tab 224) and Camera.Open(0) works fine.
    So it's most likely either the Camera not having been released properly, or something device specific.

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    So you are getting a non-null Camera instance now? And did you do the reboot?

    Are you using the example project I provided? If not, what Android SDK are you targetting? Again, what Android version is on your device (third time I am asking that now....)

    I definitely think you should not be using _mediaRecorder.SetOutputFormat etc, the Android docs are quite clear on that. They should only be used when targetting old Android (API 7 and below).

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    Yes I think It is a device issue (I have rebooted sometimes, because, in effect, camera hanghed), but It doesn't effect on the videorecorder app. Continuing to have the
    same issue on camera.start.
    the device :
    model: PWS700XA
    Android Version: 4.2.1
    kernel: 3.0.8+ [email protected] #9
    In another device:
    Samsung Galaxy Next with Android 2.2
    In some case it works, depends on encoders setting

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Strange.. but again, what API level are you targetting?

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    I'm tageting (target general) 4.2.
    Application
    minimun version 2.2 (only for tests, in production it will be 3.1)
    target version: 4.2
    I see targeting general with version prior 4.2 I have not the possibility to use:
    Camera.Open(0) and Camera.NumberOfCameras. Do I'm right ?

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭
    edited May 2013

    Yes, that should be ok.

    Well! Pfew. New thing to try, replace this line:

    _mediaRecorder.SetProfile(CamcorderProfile.Get(CamcorderQuality.High));
    

    by:

    var cameraProfile = CamcorderProfile.Get(0, CamcorderQuality.High);
    _mediaRecorder.SetProfile(cameraProfile);
    

    According to the docs, the standard CamcorderProfile.get() does this (emphasis mine):

    Returns the camcorder profile for the first back-facing camera on the device at the given quality level.

    Since you do not have a backfacing camera, this is likely to fail for the same reason why you could not get the default Camera.open() to work. CamcorderProfile.Get(0, CamcorderQuality.High) instead gets the camera profile for the front-facing camera (in your case).

    Be sure to remove the SetOutputFormat/SetVideoEncoder/SetAudioEncoder calls.

    If this still does not work, please share the content of the cameraProfile variable. It should be non-null.

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    Great Chris!! Eureka!! Now The camera is recording. I have an hang to the stop button,
    but we can work on It. As a Paradox, now I have two versions your, which is working for the tablet (with only front-face camera) and mine which is working on galaxy next (with back-face camera) :D :D :D but I can't be able to have a version which works for both. How to find an exit from this maze ? :(

    https://dl.dropboxusercontent.com/u/3342344/(your-honeycomb)RecordVideo(1).zip
    https://dl.dropboxusercontent.com/u/3342344/(mine-froyo)RecordVideo.zip

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Cool! :D

    The second link gives me a 404, can you repost?

  • StevenTheEvenStevenTheEven SEMember ✭✭✭

    @ChrisHonselaar I tried both links right now and they both works for me. Maybe it was a temporary problem when you tried.

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    Still uploading, retry in few minutes. Thanks. I have to pay you a beer ;)

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭
    edited May 2013

    var cameraProfile = CamcorderProfile.Get(CamcorderQuality.Low); mMediaRecorder.SetProfile(0,cameraProfile);<----'

    Can't use it with target framework froyo 2.2
    :-(

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭
    edited May 2013

    There is way to have a conditional framwork compilation on mono for android ?
    THe only way I got is to use alternatively like
    (pseudocode)

    if target paltform is Froyo 2.2 then

    var cameraProfile = CamcorderProfile.Get(CamcorderQuality.High);
    _mediaRecorder.SetProfile(cameraProfile);

    ......
    Camera.Open();

    elseif is honeycomb

    var cameraProfile = CamcorderProfile.Get(0,CamcorderQuality.High);
    _mediaRecorder.SetProfile(cameraProfile);

    Camera.Open(0)

    elsrif is Jellybean then

    int ncameras = Camera.NumberOfCameras;

    end if

    Any correct syntax ?

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭
    edited May 2013

    Okay yes, next challenge :)

    We are now moving into territory that is a bit unfamiliar to me as well, but I think the below should do it.

    Conditional compilation is possible, but probably not what you want in this case, as it does not solve the problem itself - you want to use the new Android API9+ methods, while still ensuring that you do not accidentally call them on older devices (where they do not exist).

    What you probably want to do is the following: just use ONE project - if you are using Visual Studio, make sure the Minimum SDK version is set to at least API 9 (Android 2.3).

    In the code, change:

    var cameraProfile = CamcorderProfile.Get(0,CamcorderQuality.High); 
    

    to:

    var camcorderProfile = ((int)Build.VERSION.SdkInt) >= 9 ? CamcorderProfile.Get(0, CamcorderQuality.High) : CamcorderProfile.Get(CamcorderQuality.High);
    

    The check against Build.VERSION.SdkInt ensures the old/simple method is used on Android 2.2.

    The same should be done for the Camera:

    return ((int) Build.VERSION.SdkInt) >= 9 ? Camera.Open(0) : Camera.Open();
    

    And there you go - one project, working on all Android versions 2.2 and up, despite differences in the available cameras, encoders etc etc :D

    Granted, I cannot test this because I do not have an Android 2.2 device around - but I checked in a 2.2 emulator AVD, and it was correctly returning Camera and CamcorderProfile instances using the old API8 methods.

    Note that while you cannot get access to a front-facing camera on Android 2.2, this is not a Xamarin limitation. There seem to be apps around that do achieve this (Skype?), but they must be resorting to low-level hardware access (using a custom driver).

    PS. Please note that adding conditional compilation statements around the API9+ method calls can still be helpful to get hard, compile-time checking if you are not somehow inadvertently calling them on an old version. But it does not change anything functionally. Read this thread for more info by the always awesome @jonp.

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭
    edited May 2013

    The issue is if I put in build->general->TargetFramework->Android 2.2 Froyo
    compiler doesn't built and breaks with this error:

    Target CoreCompile:
    Tool /Library/Frameworks/Xamarin.Android.framework/Versions/Current/bin/smcs execution started with arguments: /noconfig /debug:full /debug+ /optimize- /out:obj/Debug/RecordVideo.dll ../../RecordVideo(1)/RecordVideo/Activity1.cs ../../RecordVideo(1)/RecordVideo/Resources/Resource.designer.cs ../../RecordVideo(1)/RecordVideo/Properties/AssemblyInfo.cs /target:library /define:"DEBUG;ANDROID;ANDROID_1;ANDROID_2;ANDROID_3;ANDROID_4;ANDROID_5;ANDROID_6;ANDROID_7;ANDROID_8" /reference:/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mono/2.1/System.dll /reference:/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mono/2.1/System.Xml.dll /reference:/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/platforms/android-8/Mono.Android.dll /reference:/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mono/2.1/System.Core.dll /warn:4
    ../../RecordVideo(1)/RecordVideo/Activity1.cs(67,83): error CS1501: No overload for method Open' takes1' arguments
    /Library/Frameworks/Xamarin.Android.framework/Versions/4.6.7-4/lib/mandroid/platforms/android-8/Mono.Android.dll (Location of the symbol related to previous error)
    ../../RecordVideo(1)/RecordVideo/Activity1.cs(97,97): error CS1501: No overload for method Get' takes2' arguments
    /Library/Frameworks/Xamarin.Android.framework/Versions/4.6.7-4/lib/mandroid/platforms/android-8/Mono.Android.dll (Location of the symbol related to previous error)
    ../../RecordVideo(1)/RecordVideo/Activity1.cs(97,25): error CS0825: The contextual keyword var' may only appear within a local variable declaration ../../RecordVideo(1)/RecordVideo/Activity1.cs(99,51): error CS0841: A local variablecameraProfile' cannot be used before it is declared
    ../../RecordVideo(1)/RecordVideo/Activity1.cs(99,40): error CS1502: The best overloaded method match for Android.Media.MediaRecorder.SetProfile(Android.Media.CamcorderProfile)' has some invalid arguments /Library/Frameworks/Xamarin.Android.framework/Versions/4.6.7-4/lib/mandroid/platforms/android-8/Mono.Android.dll (Location of the symbol related to previous error) ../../RecordVideo(1)/RecordVideo/Activity1.cs(99,40): error CS1503: Argument#1' cannot convert object' expression to typeAndroid.Media.CamcorderProfile'
    /Library/Frameworks/Mono.framework/Versions/2.10.12/lib/mono/4.0/Microsoft.CSharp.Targets: error : Compiler crashed with code: 1.
    Task "Csc" execution -- FAILED
    Done building target "CoreCompile" in project "/Users/utente/Xamarin-Projects/RecordVideo(1)/RecordVideo/RecordVideo.csproj".-- FAILED

    Done building project "/Users/utente/Xamarin-Projects/RecordVideo(1)/RecordVideo/RecordVideo.csproj".-- FAILED

    /Library/Frameworks/Mono.framework/Versions/2.10.12/lib/mono/4.0/Microsoft.CSharp.Targets: Error: Compiler crashed with code: 1. (RecordVideo)

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    My instructions were for Visual Studio, as I mentioned.

    For Xamarin Studio, it works a bit differently; there you should set Build > General > Target framework to Android 2.3 or higher - NOT 2.2 Froyo.

    Under Build > Android Application > Minimum Android version should be set to API Level 8 (Android 2.2), Target Android version should be set to API Level 9 or higher.

    Confusing, I know :) But that's how it works.

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    This is my project, builds and runs on Froyo and up.

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    Yes Chris! Exactly. In the meantime I have tried some combination, and now I get It
    You have bee so gently to fallow me. Thanks, thanks very much.
    I saw that changing orientation during recording, recording stops. There is a way to prevent it? Do I'm asking too much ? :)

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Rotating will cause the preview surface to reset, which stops the recording.

    You can disable rotation during recording, by setting RequestedOrientation to SCREEN_ORIENTATION_NOSENSOR (might look slightly different in XamDroid)

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    WHere and how ? Sorry Chris but I'm a beginner.

Sign In or Register to comment.