13

私はビデオ会議プロジェクトに取り組んでいます。私のビデオ ディスプレイはサーフェス ビューを使用しています。ビデオ通話中に、着信フレームのアスペクト比が変化する可能性があります。だから私はそれのために次のコードを試しました

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*****************************************");
}

呼び出しの最初にこの関数を呼び出すと、すべて問題ありません。私の問題は、アスペクト比を変更するための呼び出しの間にこの関数を呼び出すと、次のフレームを表示するのに時間がかかりすぎることです。時々、ビデオが動かなくなることさえあります。

で表面を破壊して再現してみました

myVideoSurface.setVisibility(VIEW.GONE);

しかし、サーフェスは作成されていません。

ビデオのデコードに Mediacodec を使用していますが、解像度が変更されると通知が届きます。

既にビデオが再生されているときに surfaceView のサイズを変更するために、他にすべきことはありますか?

手伝ってくれてありがとう.........................

4

2 に答える 2

3

ここに画像の説明を入力 この問題は、このように解決できます。

于 2019-12-09T03:23:19.530 に答える