2013-12-10 31 views
7

Bir video konferans projesi üzerinde çalışıyorum. Video ekranım yüzey görünümünü kullanıyor. Şimdi bir görüntülü arama sırasında gelen kareler için en boy oranı değişikliği şansı var. Bu yüzden aşağıdaki kodu denedim.En boy oranı için yüzey görünümünü yeniden boyutlandırma android video göstergesinde değişiklik

public void surfaceResize() { 

    // WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 
    Point size = new Point(); 
    int screenWidth = 0; 
    //Get the SurfaceView layout parameters 

    float aspectRatio = (float) recv_frame_width/recv_frame_height; 

    if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) 
    { 
     //Get the width of the screen 
     getWindowManager().getDefaultDisplay().getSize(size); 
     screenWidth = size.x; 

     //Set the width of the SurfaceView to the width of the screen 
     surflp.width = screenWidth; 

     //Set the height of the SurfaceView to match the aspect ratio of the video 
     //be sure to cast these as floats otherwise the calculation will likely be 0 
     surflp.height = (int) ((1/aspectRatio) * (float)screenWidth); 

     //Commit the layout parameters 

    } else { 

     size.x = size.y = 0; 
     //Get the width of the screen 
     getWindowManager().getDefaultDisplay().getSize(size); 

     int screenHeight = size.y; 

     //Set the width of the SurfaceView to the width of the screen 
     surflp.height = screenHeight; 

     //Set the width of the SurfaceView to match the aspect ratio of the video 
     //be sure to cast these as floats otherwise the calculation will likely be 0 
     surflp.width = (int) (aspectRatio * (float)screenHeight); 

     //Commit the layout parameters 
     // code to do for Portrait Mode   
    } 
    surflp.addRule(RelativeLayout.CENTER_HORIZONTAL); 
    surflp.addRule(RelativeLayout.CENTER_VERTICAL); 

    if(myVideoSurfaceView != null) 
     myVideoSurfaceView.setLayoutParams(surflp); 
    System.out.println("Surface resized*****************************************"); 
} 

Çağrının başlangıcında bu işlevi çağırırsam her şey yolunda. Sorunum, en boy oranını değiştirmek için bir çağrı arasında bu işlevi çağırdığımda, bir sonraki kareyi görüntülemenin çok zaman almasıdır. Bazen video bile sıkışır.

Ben

myVideoSurface.setVisibility(VIEW.GONE); 

ile yüzeye yok etmek ve yeniden çalıştı Ama yüzey oluşturulur almıyor.

Video kod çözme için Mediacodec kullanıyorum Çözünürlük değişikliği olduğunda bildirim alırım.

Zaten bir video oynatılırken bir yüzeyi yeniden boyutlandırmak için yapmam gereken başka bir şey var mı?

+0

Eğer senin Sorun çözüldü, lütfen bir cevabı kabul edin. Yani soru "cevapsız" listesinde görünmüyor. –

+0

burada iyi bir çözümdür (http://stackoverflow.com/a/33670521/2220110) –

cevap

22

Merhaba kodunun altına deneyin yardım için

Teşekkür .........................:

private void setVideoSize() { 

      // // Get the dimensions of the video 
      int videoWidth = mediaPlayer.getVideoWidth(); 
      int videoHeight = mediaPlayer.getVideoHeight(); 
      float videoProportion = (float) videoWidth/(float) videoHeight; 

      // Get the width of the screen 
      int screenWidth = getWindowManager().getDefaultDisplay().getWidth(); 
      int screenHeight = getWindowManager().getDefaultDisplay().getHeight(); 
      float screenProportion = (float) screenWidth/(float) screenHeight; 

      // Get the SurfaceView layout parameters 
      android.view.ViewGroup.LayoutParams lp = surfaceView.getLayoutParams(); 
      if (videoProportion > screenProportion) { 
       lp.width = screenWidth; 
       lp.height = (int) ((float) screenWidth/videoProportion); 
      } else { 
       lp.width = (int) (videoProportion * (float) screenHeight); 
       lp.height = screenHeight; 
      } 
      // Commit the layout parameters 
      surfaceView.setLayoutParams(lp); 
     } 
+0

Hızlı yanıt için teşekkürler kyogs. Ama ben de benzer bir recv_frame_width yapıyorum ve recv_frame_height geçerli kare yüksekliği ve genişliği. Video oynatıldığından beri bu değişiklik için SurfaceView ile yapılacak başka bir şey olup olmadığını bilmek istiyorum. Yüzey görünümünden –

+0

görüntü yükseklik ve genişliğini alabilirsiniz. – kyogs

+0

@ kyogs Ya biliyorum ama bu olmadan da yeni genişlik ve yükseklik ve en boy oranına sahibim. ama sorun, onun için çok fazla zaman alan ve bazen video sıkışıp kaldığım SurfaceView'ımı yeniden boyutlandırmaya çalıştığımda ortaya çıkıyor. –

İlgili konular