Skip to content

Commit

Permalink
Call Looper.prepareMainLooper() to avoid exception
Browse files Browse the repository at this point in the history
Some devices internally create a Handler when creating an input Surface,
causing an exception:

> Surface: java.lang.RuntimeException: Can't create handler inside
> thread that has not called Looper.prepare()

As a workaround, call Looper.prepareMainLooper() beforehand.

Fixes:
 - <#240>
 - <#921>

Signed-off-by: Romain Vimont <[email protected]>
  • Loading branch information
olbb authored and rom1v committed Nov 9, 2019
1 parent b08a983 commit 9da4c93
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.media.MediaCodecInfo;
import android.media.MediaFormat;
import android.os.IBinder;
import android.os.Looper;
import android.view.Surface;

import java.io.FileDescriptor;
Expand Down Expand Up @@ -54,6 +55,11 @@ public boolean consumeRotationChange() {
}

public void streamScreen(Device device, FileDescriptor fd) throws IOException {
// Some devices internally create a Handler when creating an input Surface, causing an exception:
// "Can't create handler inside thread that has not called Looper.prepare()"
// <https://github.com/Genymobile/scrcpy/issues/240>
Looper.prepareMainLooper();

MediaFormat format = createFormat(bitRate, frameRate, iFrameInterval);
device.setRotationListener(this);
boolean alive;
Expand Down

0 comments on commit 9da4c93

Please sign in to comment.