20
20
import android .os .Looper ;
21
21
import android .os .Handler ;
22
22
import android .os .Build ;
23
+ import android .os .Bundle ;
23
24
import android .view .Display ;
25
+ import android .util .Log ;
26
+ import android .content .Context ;
27
+ import android .content .res .Configuration ;
24
28
25
29
/**
26
30
* 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
46
50
private MediaProjectionManager mediaProjectionManager ;
47
51
private WindowManager windowManager ;
48
52
private boolean isPortrait ;
53
+ private Context context ;
49
54
50
55
/**
51
56
* Constructs a new Screen Capturer.
@@ -56,10 +61,12 @@ public class OrientationAwareScreenCapturer implements VideoCapturer, VideoSink
56
61
* @param mediaProjectionCallback MediaProjection callback to implement application specific
57
62
* logic in events such as when the user revokes a previously granted capture permission.
58
63
**/
59
- public OrientationAwareScreenCapturer (Intent mediaProjectionPermissionResultData ,
64
+ public OrientationAwareScreenCapturer (Context context ,
65
+ Intent mediaProjectionPermissionResultData ,
60
66
MediaProjection .Callback mediaProjectionCallback ) {
61
67
this .mediaProjectionPermissionResultData = mediaProjectionPermissionResultData ;
62
68
this .mediaProjectionCallback = mediaProjectionCallback ;
69
+ this .context = context ;
63
70
}
64
71
65
72
public void onFrame (VideoFrame frame ) {
@@ -76,9 +83,7 @@ public void onFrame(VideoFrame frame) {
76
83
}
77
84
78
85
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 ;
82
87
}
83
88
84
89
0 commit comments