androidandroid-activityandroid-cameragoogle-glass

Video recording function crashes on Glasses, but not on Phone


Any idea what's going on? Error messages keep prompting this: MediaRecorder start failed: -19 and android.media.MediaRecorder.start(Native Method)

I'm a newbie in the Android programming world and I am so confused. Why does it crash on the glasses and works perfectly on phone. I'm currently developing a simple video recording app for the Vuzix Smartglasses.

This is what I have so far:

     @Override
     public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);

           recording = false;

           mediaRecorder = new MediaRecorder();
           initMediaRecorder();

           setContentView(R.layout.video_main);

           SurfaceView myVideoView = (SurfaceView)findViewById(R.id.videoview);
           surfaceHolder = myVideoView.getHolder();
           surfaceHolder.addCallback(this);
           surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

           myButton = (Button)findViewById(R.id.mybutton);
           myButton.setOnClickListener(myButtonOnClickListener);
       }

       private Button.OnClickListener myButtonOnClickListener
       = new Button.OnClickListener(){

     @Override
     public void onClick(View arg0) {
         // TODO Auto-generated method stub
         if(recording)
         {
             mediaRecorder.stop();
             mediaRecorder.release();
             finish();
         }
         else
         {
             mediaRecorder.start();
             recording = true;
             myButton.setText("STOP");
         }
     }};

    @Override
    public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
     // TODO Auto-generated method stub

    }
    @Override
    public void surfaceCreated(SurfaceHolder arg0) {
     // TODO Auto-generated method stub
     prepareMediaRecorder();
    }
    @Override
    public void surfaceDestroyed(SurfaceHolder arg0) {
     // TODO Auto-generated method stub

    }

    private void initMediaRecorder(){

        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
        CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
        mediaRecorder.setProfile(camcorderProfile_HQ);
        mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
        //mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
        //mediaRecorder.setMaxFileSize(5000000); // Set max file size 5M
    }

    private void prepareMediaRecorder(){

        mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());

        try 
        {
            mediaRecorder.prepare();
        } 
        catch (IllegalStateException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

Solution

  • Todd Ferguson, Senior Support Specialist with Vuzix here. I was advised of this thread by one of our customers, and I figured I'd post the answer I gave him here, to help you out as well.

    If you have any questions about this, the best way to reach me with those questions is todd_ferguson@vuzix.com.

    Hmm. Apparently that method of using a TextureView doesn’t seem to work for us. I had to change it back to a SurfaceView to get it working. I also had to set the video framerate to 24 and increase the resolution since the function getOptimalPreviewSize() was being based on the size of the preview surface and returned a weird resolution.
    I’ll add the TextureView weirdness to the bug list as that should be working in our API version. The framerate issue is a camera driver problem and a known bug. Thank you for bringing this to our attention. We’ll address these issues in an upcoming build.

    Regards,

    Todd R Ferguson