Record video/audio on Android

Discussion in 'Troubleshooting' started by TomImage+, Sep 4, 2015.

  1. TomImage+

    TomImage+ New Member

    Joined:
    Sep 4, 2015
    Messages:
    5
    Likes Received:
    1
    Hi,

    I have tried several different types of code to record video and audio on android.
    I am using the UDOO dual with android 4.4 kitkat.

    I try to use the MediaRecorder. But is does not seems to find a correct videoSource. When i try to set the videoSize or VideoEncoder or VideoFramerate the software crashes without usefull debug info. Even the try/catch block gives an empty exception.

    I hope someone can help me

    Thanks in advance,
    Tom
     
  2. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    Hi there TomImage+,
    which camera are u using?
    Cheers
     
  3. TomImage+

    TomImage+ New Member

    Joined:
    Sep 4, 2015
    Messages:
    5
    Likes Received:
    1
    Oh i forgot to mention it. how dumb of me,

    I am using the MIPI 5MP AF Camera
     
  4. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    A few questions then:
    Do you have granted permission in you android manifest?

    Code:
          <uses-permission android:name="android.permission.CAMERA" />
          <uses-feature android:name="android.hardware.camera" />
    try to use something like this to get the camera preview, to check if it work

    Code:
       public class MainActivity extends Activity implements TextureView.SurfaceTextureListener {
    
        private Camera mCamera;
        private Camera.CameraInfo info;
        private TextureView mTextureView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
            mTextureView = (TextureView) findViewById(R.id.camera_texture);
            mTextureView.setSurfaceTextureListener(this);
    }
    
    
    @Override
        public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
    
        Log.i(DEBUG, "onSurfaceTextureAvailable");
            info = new Camera.CameraInfo();
            for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
               Camera.getCameraInfo(i, info);
    
                Log.i(DEBUG, "info: "+ info.facing);
    
    //mCamera = Camera.open(i);
    
          }
    
    
            //make portrait
            //mCamera.setDisplayOrientation(90);
    
    try {
    /* Tell the camera to write onto our textureView mTextureView */
    mCamera.setPreviewTexture(surfaceTexture);
    mCamera.startPreview();
    } catch (IOException ioe) {
    Log.e("camera-reverse", ioe.getMessage());
    }
    
    }
    
    @Override
        public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
        Log.i(DEBUG, "onSurfaceTextureDestroyed");
            if (null != mCamera) {
                mCamera.stopPreview();
                mCamera.release();
            }
            return true;
        }
    
        @Override
        public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
        //Log.i(DEBUG, "onSurfaceTextureUpdated");
        }
     
    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture arg0, int arg1, int arg2) {
    // TODO Auto-generated method stub
    }
     
    TomImage+ likes this.
  5. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    The indentation is not properly done, forgive me for that.
     
  6. TomImage+

    TomImage+ New Member

    Joined:
    Sep 4, 2015
    Messages:
    5
    Likes Received:
    1
    That is no problem.
    i had the permissions in my app so that was not the issue
    I do get the preview now! Thank you

    How do i record the video now preferrably with the audio stream from the mic input
     
  7. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    Never done this before, anyway it's standard Android programming.
     
  8. TomImage+

    TomImage+ New Member

    Joined:
    Sep 4, 2015
    Messages:
    5
    Likes Received:
    1
    Thank you very much!
     
    Andrea Rovai likes this.

Share This Page