2020import android .os .Looper ;
2121import android .os .Handler ;
2222import android .os .Build ;
23+ import android .os .Bundle ;
2324import android .view .Display ;
25+ import android .util .Log ;
26+ import android .content .Context ;
27+ import android .content .res .Configuration ;
2428
2529/**
2630 * An copy of ScreenCapturerAndroid to capture the screen content while being aware of device orientation
@@ -46,6 +50,7 @@ public class OrientationAwareScreenCapturer implements VideoCapturer, VideoSink
4650 private MediaProjectionManager mediaProjectionManager ;
4751 private WindowManager windowManager ;
4852 private boolean isPortrait ;
53+ private Context context ;
4954
5055 /**
5156 * Constructs a new Screen Capturer.
@@ -56,10 +61,12 @@ public class OrientationAwareScreenCapturer implements VideoCapturer, VideoSink
5661 * @param mediaProjectionCallback MediaProjection callback to implement application specific
5762 * logic in events such as when the user revokes a previously granted capture permission.
5863 **/
59- public OrientationAwareScreenCapturer (Intent mediaProjectionPermissionResultData ,
64+ public OrientationAwareScreenCapturer (Context context ,
65+ Intent mediaProjectionPermissionResultData ,
6066 MediaProjection .Callback mediaProjectionCallback ) {
6167 this .mediaProjectionPermissionResultData = mediaProjectionPermissionResultData ;
6268 this .mediaProjectionCallback = mediaProjectionCallback ;
69+ this .context = context ;
6370 }
6471
6572 public void onFrame (VideoFrame frame ) {
@@ -76,9 +83,7 @@ public void onFrame(VideoFrame frame) {
7683 }
7784
7885 private boolean isDeviceOrientationPortrait () {
79- final int surfaceRotation = windowManager .getDefaultDisplay ().getRotation ();
80-
81- return surfaceRotation != Surface .ROTATION_90 && surfaceRotation != Surface .ROTATION_270 ;
86+ return context .getResources ().getConfiguration ().orientation == Configuration .ORIENTATION_PORTRAIT ;
8287 }
8388
8489
0 commit comments