2017-05-20 64 views
3

案例1:GlSurfaceView setZMediaOrder導致視頻到其父母在外面玩

GLSurfaceView 
| 
FrameLayout 
| 
TextureView 
| 
VideoRecording 

所以在這裏我有一個GLSurfaceView,基於用戶輸入,我在它的上面添加一個正方形FrameLayout(尺寸設定使用的LayoutParams),然後在這個新添加的FrameLayout,然後錄製視頻的頂部添加TextureView,正如預期的那樣,無論什麼相機選擇,我得到一個正方形的預覽。

案例2:

GLSurfaceView 
| 
FrameLayout 
| 
GLSurfaceView 
| 
VideoPlayback

在這種情況下-1通過從已經以前TextureView記錄我加入另一個GLSurfaceView視頻後添加FrameLayout。此前,我只聽到播放無任何視頻的聲音,但後來我碰到的例子,其使用
setZOrderMediaOverlay(true);

setZOrderOnTop(true)
現在在視頻播放的,而是其母公司中玩耍,其在9打/ 16的縱橫比。正如前面提到的,預期的行爲是方形的視頻(在FrameLayout裏的尺寸)。

我怎樣才能得到背景視頻頂部新加入的視頻,而無需得到它了其父母的界限的。

回答

0

我認爲你需要檢查媒體播放器的寬高比,並設置根據是,使用相對佈局而不是框架佈局,並設置重心,並執行該代碼:

MediaPlayer.OnVideoSizeChangedListener mOnVideoSizeChangedListener = new MediaPlayer.OnVideoSizeChangedListener() { 

     @Override 
     public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { 

      setAspectRatio(mp, width, height); 

     } 
    }; 

,並創建一個方法,並設置根據此視頻佈局參數:

private void setAspectRatio(MediaPlayer mediaPlayer, int videoWidth, int videoHeight) 
{ 
    if(mediaPlayer != null) 
    { 

     DisplayMetrics displayMetrics = new DisplayMetrics(); 
     getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 
     int height = displayMetrics.heightPixels; 
     int width = displayMetrics.widthPixels; 

     ViewGroup.LayoutParams videoParams = getLayoutParams(); 


     if (videoWidth > videoHeight) 
     { 
      videoParams.width = width; 
      videoParams.height = width * videoHeight/videoWidth; 
     } 
     else 
     { 
      videoParams.width = height * videoWidth/videoHeight; 
      videoParams.height = height; 
     } 

     // Commit params 
     surfaceView.setLayoutParams(videoParams); 
    } 
} 
+0

對不起,苛刻,問題不在於調整表面大小。 –