Skip to content

Commit 0c57783

Browse files
added guards for empty view and make sure captured is runing on the main UI thread (#888)
1 parent 2d1a27b commit 0c57783

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

android/src/main/java/com/opentokreactnative/OTScreenCapturer.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.graphics.Canvas;
66
import android.os.Handler;
77
import android.view.View;
8+
import android.os.Looper;
89

910
import com.opentok.android.BaseVideoCapturer;
1011

@@ -21,15 +22,27 @@ public class OTScreenCapturer extends BaseVideoCapturer {
2122
private Bitmap bmp;
2223
private Canvas canvas;
2324

24-
private Handler mHandler = new Handler();
25+
private Handler mHandler = new Handler(Looper.getMainLooper());
2526

2627
private Runnable newFrame = new Runnable() {
2728
@Override
2829
public void run() {
2930
if (capturing) {
31+
// Check if the view is attached and has dimensions
32+
if (contentView == null || !contentView.isAttachedToWindow()) {
33+
mHandler.postDelayed(newFrame, 1000 / fps);
34+
return;
35+
}
36+
3037
int width = contentView.getWidth();
3138
int height = contentView.getHeight();
3239

40+
// Skip frame if dimensions are zero
41+
if (width <= 0 || height <= 0) {
42+
mHandler.postDelayed(newFrame, 1000 / fps);
43+
return;
44+
}
45+
3346
if (frame == null ||
3447
OTScreenCapturer.this.width != width ||
3548
OTScreenCapturer.this.height != height) {

0 commit comments

Comments
 (0)