Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set size for Media Recorder with notch display

I'm using MediaRecorder to record the surface, So I'm defining the video size to the MediaRecorder before preparing

Size size = getWindowManager().getDefaultDisplay().getSize(size);
... preparing the media recorder
mediaRecorder.setVideoSize(size.x, size.y);

So it is working fine without notch, when comes to the devices with notch the video is recorded as black.

Please help me

Thanks in Advance

like image 449
Jagadesh Seeram Avatar asked Jul 05 '19 03:07

Jagadesh Seeram


1 Answers

Detect and subtract the notch height

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

    Log.d("height",""+height);

    //Detect notch
    int statusBarHeight = 0;
    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        statusBarHeight = getResources().getDimensionPixelSize(resourceId);
    }

    if (statusBarHeight > Math.round( 24 * (displayMetrics.densityDpi / 160f))) {
        height -= statusBarHeight;
    }

    Log.d("height",""+height);
like image 190
shb Avatar answered Nov 07 '22 20:11

shb