Quando registro video da MediaRecorder, registra sempre in modalità orizzontale, indipendentemente dall'orientamento reale del dispositivo. Come forzare MediaRecorder/Fotocamera utilizzare l'orientamento reale?come cambiare l'orientamento del video in MediaRecorder a ritratto
risposta
fare riferimento a Camera.Parameters.setRotation() per ulteriori informazioni.
C'è un esempio lì e invece di chiamare setRotation (rotazione) tenta di chiamare mediaRecorder.setOrientationHint (rotazione) durante la registrazione di video.
'mediaRecorder.setOrientationHint' cambia solo l'orientamento del video in uscita, non l'orientamento dell'anteprima. – Cat
Inoltre, 'setOrientationHint' funziona solo per i flussi MPEG4. Altri (come MPEG2TS) non implementano questa opzione (viene silenziosamente ignorata). – Lekensteyn
@Cat hai ragione, hai qualche idea su come sistemarlo nell'anteprima? !! –
Date un'occhiata alla documentazione qui
http://developer.android.com/guide/topics/media/camera.html#capture-video
L'insidia più comune con l'questo esempio è il setcamera(). È NECESSARIO IMPOSTARE IMMEDIATAMENTE LA VIDEOCAMERA DOPO AVER FATTO il MediaRecorder altrimenti si otterranno errori.
Camera mCamera = getCameraInstance();
// adjust the camera the way you need
mCamera.setDisplayOrientation(90);
MediaRecorder recorder = new MediaRecorder();
recorder.setCamera(mCamera);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
recorder.setOutputFile(filePath);
// add any limits
recorder.setMaxDuration(50000); // 50 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
Spero che questo aiuti qualcuno. In bocca al lupo!!
questo codice fallirà A MENO che chiami 'mCamera.unlock();' prima di 'recorder.setCamera (mCamera)': http://developer.android.com/reference/android/hardware/Camera.html#unlock() – Cat
Anch'io ho bloccato questo problema. Ho scoperto che è possibile utilizzare la funzione setOrientationHint (API 9). Chiamare questa funzione prima di chiamare MediaRecorder.prepare(). È possibile impostare il grado di orientamento per il video in uscita.
Spero che ti aiuti, buona fortuna!
Aggiungere le seguenti due righe di codice:
Camera.setDisplayOrientation(90); // use for set the orientation of the preview
mRecorder.setOrientationHint(90); // use for set the orientation of output video
prima:
mRecorder.setCamera(mCamera);
esempio completa:
mRecorder = new MediaRecorder();
// Both are required for Portrait Video
mCamera.setDisplayOrientation(90);
mRecorder.setOrientationHint(90);
// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mRecorder.setCamera(mCamera);
// Step 2: Set sources
mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
mRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P));
mMediaRecorder = new MediaRecorder();
mServiceCamera.setDisplayOrientation(90);
mMediaRecorder.setOrientationHint(90);
mServiceCamera.unlock();
mMediaRecorder.setCamera(mServiceCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
che dire insieme 'android: screenOrientation =" paesaggio "' della tua CameraActivity nel manifest – IgniteCoders