2016-05-25 1 views
5

J'utilise google officiel sample pour contourner l'enregistrement vidéo en utilisant Camera API 2. mais le problème est que je ne suis pas en mesure de le faire en plein écran que j'ai limité l'orientation de l'écran uniquement à portrait.Voici le xml j'ai édité et le official xml.Appareil photo 2: Impossible d'enregistrer la vidéo en plein écran?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <AutoFitTextureView 
     android:id="@+id/texture" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" /> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

     <Button 
      android:id="@+id/video" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="@string/label_record" /> 

     <ImageView 
      android:id="@+id/info" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical|right" 
      android:contentDescription="Description" 
      android:padding="20dp" 
      android:src="@drawable/ic_more" /> 

    </FrameLayout> 

</RelativeLayout> 

Je pense ici est le réglage de la taille de l'écran vidéo par rapport d'aspect à la TextureView mais je ne pouvais pas le faire à plein écran. Toute aide est grandement appréciée.

mVideoSize = chooseVideoSize(map.getOutputSizes(MediaRecorder.class)); 
mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, mVideoSize); 
int orientation = getResources().getConfiguration().orientation; 
if (orientation == Configuration.ORIENTATION_LANDSCAPE) { 
    mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); 
} else { 
    mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); 
} 

enter image description here

Répondre

1

Vous devez gérer la taille de l'aperçu pour contrôler la taille de l'écran d'enregistrement. utilisez la même méthode chooseVideoSize pour faire votre aperçu en plein écran en obtenant la classe de tailles de sortie SurfaceTexture.

private static Size chooseVideoSize(Size[] choices) { 
     for (Size size : choices) { 
      if (size.getWidth() == size.getHeight() * 4/3 && size.getWidth() <= 1080) { 
       return size; 
      } 
     } 
     Log.e(TAG, "Couldn't find any suitable video size"); 
     return choices[choices.length - 1]; 
    } 

qui est

mPreviewSize = chooseVideoSize(map.getOutputSizes(SurfaceTexture.class)); 
+0

Oui .. Il est working..thanks :) – Stella

1

Peut-être que vous pourriez mettre en œuvre une méthode de transformation qui redimensionne et tourne la TextureView à l'orientation correcte.

private void transformImage(int width, int height) { 
    if (mPreviewSize == null || mTextureView == null) { 
     return; 
    } 
    Matrix matrix = new Matrix(); 
    int rotation = getWindowManager().getDefaultDisplay().getRotation(); 
    RectF textureRectF = new RectF(0, 0, width, height); 
    RectF previewRectF = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth()); 
    float centerX = textureRectF.centerX(); 
    float centerY = textureRectF.centerY(); 
    if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) { 
     previewRectF.offset(centerX - previewRectF.centerX(), 
       centerY - previewRectF.centerY()); 
     matrix.setRectToRect(textureRectF, previewRectF, Matrix.ScaleToFit.FILL); 
     float scale = Math.max((float) width/mPreviewSize.getWidth(), 
       (float) height/mPreviewSize.getHeight()); 
     matrix.postScale(scale, scale, centerX, centerY); 
     matrix.postRotate(90 * (rotation - 2), centerX, centerY); 
    } 
    mTextureView.setTransform(matrix); 
} 

Après cela, vous devez appeler la méthode de transformation onResume:

public void onResume() { 
    super.onResume(); 
    if (mTextureView.isAvailable()) { 
     transformImage(mTextureView.getWidth(), mTextureView.getHeight()); 
    } else { 
     mTextureView.setSurfaceTextureListener(mSurfaceTextureListener); 
    } 
} 

Et SurfaceTextureListener.Callback:

private TextureView.SurfaceTextureListener mSurfaceTextureListener = 
     new TextureView.SurfaceTextureListener() { 
      @Override 
      public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { 
       transformImage(width, height); 
      } 

      @Override 
      public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { 
      } 

      @Override 
      public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { 
       return false; 
      } 

      @Override 
      public void onSurfaceTextureUpdated(SurfaceTexture surface) { 
      } 
     }; 

Source.