启动指令流引擎,接收并渲染云手机画面。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | public class Activity implements BaseActivity { private VmiSurfaceView surfaceView; private Boolean newlyCreated = true; private int guestWidth = 1080; private int guestHeight = 1920; DisplayMetrics metric = new DisplayMetrics(); protected void onCreate(Bundle savedInstanceState) { WindowManager wm = (WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE); wm.getDefaultDisplay().getRealMetrics(metric); Log.i(TAG, "width pixels:" + metric.widthPixels + ", height pixels:" + metric.heightPixels + ",densityDpi:" + metric.densityDpi); guestWidth = metric.widthPixels; guestHeight = metric.heightPixels; initSurfaceHolderCallback(surfaceView.getHolder()); } private void initSurfaceHolderCallback(SurfaceHolder surfaceHolder) { surfaceHolder.addCallback(new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder surfaceHolder) { // 首次创建 newlyCreated = true; } @Override public void surfaceChanged(SurfaceHolder inSurfaceHolder, int format, int width, int height) { if (!newlyCreated) { return; } newlyCreated = false; // 由于启动接口涉及socket连接,建议放到线程中调用 threadPool.submit(new ConnectRunable()); } @Override public void surfaceDestroyed(SurfaceHolder surfaceHolder) { newlyCreated = false; } }); } class ConnectRunable implements Runnable { @Override public void run() { // 调用指令流引擎启动接口 final int startResult = engine.start(surfaceView.getHolder().getSurface(), guestWidth, guestHeight, metric.densityDpi); runOnUiThread(new Runnable() { @Override public void run() { if (startResult == InstructionEngine.VMI_CLIENT_START_FAIL) { // 连接失败 } else { // 连接成功或者已经连接 } } }); } } |