Call Looper.prepareMainLooper() to avoid exception
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: - <https://github.com/Genymobile/scrcpy/issues/240> - <https://github.com/Genymobile/scrcpy/issues/921> Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
parent
b08a98324d
commit
e282100d0b
1 changed files with 11 additions and 0 deletions
|
@ -7,6 +7,7 @@ import android.media.MediaCodec;
|
||||||
import android.media.MediaCodecInfo;
|
import android.media.MediaCodecInfo;
|
||||||
import android.media.MediaFormat;
|
import android.media.MediaFormat;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.Looper;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
|
@ -54,6 +55,16 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void streamScreen(Device device, FileDescriptor fd) throws IOException {
|
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>
|
||||||
|
//
|
||||||
|
// Use Looper.prepareMainLooper() instead of Looper.prepare() to avoid a NullPointerException:
|
||||||
|
// "Attempt to read from field 'android.os.MessageQueue android.os.Looper.mQueue'
|
||||||
|
// on a null object reference"
|
||||||
|
// <https://github.com/Genymobile/scrcpy/issues/921>
|
||||||
|
Looper.prepareMainLooper();
|
||||||
|
|
||||||
MediaFormat format = createFormat(bitRate, frameRate, iFrameInterval);
|
MediaFormat format = createFormat(bitRate, frameRate, iFrameInterval);
|
||||||
device.setRotationListener(this);
|
device.setRotationListener(this);
|
||||||
boolean alive;
|
boolean alive;
|
||||||
|
|
Loading…
Reference in a new issue