Skip to content

Commit 236da14

Browse files
authored
Merge pull request #22 from GetStream/fix/fix-orientation-awareness
fix device orientation check for screen capturing
2 parents c239fe7 + 506e736 commit 236da14

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Diff for: android/src/main/java/io/getstream/webrtc/flutter/GetUserMediaImpl.java

+1
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ private void getDisplayMedia(final Result result, final MediaStream mediaStream,
515515
VideoCapturer videoCapturer = null;
516516
videoCapturer =
517517
new OrientationAwareScreenCapturer(
518+
applicationContext,
518519
mediaProjectionData,
519520
new MediaProjection.Callback() {
520521
@Override

Diff for: android/src/main/java/io/getstream/webrtc/flutter/OrientationAwareScreenCapturer.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
import android.os.Looper;
2121
import android.os.Handler;
2222
import android.os.Build;
23+
import android.os.Bundle;
2324
import 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

Comments
 (0)