2014-01-18 79 views
7

我需要從我的應用程序只使用前置攝像頭拍攝視頻。我正在使用意圖執行此操作。意圖在Android中拍攝視頻

Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri); 
intent.putExtra("android.intent.extra.durationLimit", 30); 
intent.putExtra("android.intent.extras.CAMERA_FACING", 1); //to open front facing camera 
startActivityForResult(intent, VIDEO_CAPTURE); 

當我運行該應用程序時,我能夠使用前置攝像頭拍攝視頻。但是,假設當我點擊我的錄製視頻按鈕並打開相機視圖時。在那個用戶去並改變相機後面的相機,然後總是我的意圖是打開後方相機只有在那之後。它沒有走線

intent.putExtra("android.intent.extras.CAMERA_FACING", 1); 

有人能告訴我最新的問題是什麼,它是否能夠使用意圖解決?

+1

設置此意圖,不會爲每個設備工作。 –

+0

但它的第一次工作..即使我的相機設置是後置攝像頭.. – Mathew

+1

檢查此鏈接,它可能會幫助你 - http://stackoverflow.com/questions/19667094/intent-does-not-set-相機參數 –

回答

3

沒有可靠的方式來使用意圖始終顯示前置攝像頭,至少不是在所有設備上。唯一可行的方法是創建一個SurfaceView並自己捕捉視頻。

2

見,如果這個工程:

try { 
    if (Camera.getNumberOfCameras() == 2) { 
     if (frontCamera) { 
      frontCamera = false; 
      prCamera.stopPreview(); 
      prMediaRecorder.release(); 
      prMediaRecorder = null; 
      prCamera.release(); 
      prCamera = null; 
     } else { 

      frontCamera = true; 
      prCamera.stopPreview(); 
      prMediaRecorder.release(); 
      prMediaRecorder = null; 
      prCamera.release(); 
      prCamera = null; 
     } 
     Intent intent = new Intent(VideoCapture_New.this, 
       VideoCapture_New.class); 
     startActivity(intent); 
    } else { 
     Toast.makeText(VideoCapture_New.this, 
       "Your device doesn't contain Front Camera.", 
       Toast.LENGTH_SHORT).show(); 
    } 
} catch (Exception e) { 
    e.printStackTrace(); 
    Toast.makeText(VideoCapture_New.this, 
      "Your device is not compatible for Front Camera.", 
      Toast.LENGTH_SHORT).show(); 

} 

來源:Front camera in android

否則,你可以使用Android的KeyEvents觸發相機開關的按鈕按下,如果視頻開始回相機上錄製。 KeyEvents需要精確計時,否則它們會觸發其他事情!檢查:KeyEvent

此外,如果你正在使用的

mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)); 

此簽名CamcorderProfile.get()默認爲朝後相機的配置文件。 因此,而不是使用這一點,使用:

public static CamcorderProfile get (int cameraId, int quality) 

mediaRecorder.setVideoFrameRate(15); 

使用的任何值,1 - 15爲幀速率。 查詢this瞭解更多詳情。

希望這會有所幫助。

+3

使用CTRL + SHIFT + I縮進和格式化代碼。 –

2

創建確保只使用前置攝像頭

您的自定義視頻拍攝應用程序,我認爲這是做到這一點的唯一方法。

希望有所幫助。