How to open the front facing camera and record video in android

前端 未结 2 755
轻奢々
轻奢々 2021-01-16 13:36

How do I open the front camera using surface view, and record video in android 3.1? Can anybody provide sample code?

2条回答
  •  耶瑟儿~
    2021-01-16 14:24

    This should works, assuming you have created the surface:

    int cameraType = 1; // front
    camera = Camera.open(cameraType);
    
    m_recorder = new MediaRecorder();
    m_recorder.setPreviewDisplay(m_BeMeSurface);    
    m_recorder.setCamera(camera);
    m_recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    m_recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    m_recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    m_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    m_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
    m_recorder.setMaxDuration((int) MAX_TIME); 
    m_recorder.setOnInfoListener(m_BeMeSelf);
    m_recorder.setVideoSize(320, 240); 
    m_recorder.setVideoFrameRate(15); 
    m_recorder.setOutputFile(m_path);
    
    m_recorder.prepare();
    m_recorder.start();
    

    Note that not all camera hardware support front camera video recording. In such a case, the back camera is used. Call this api to find out which video recording sizes are avaliable

提交回复
热议问题