Calling the Interface Function for Starting the Engine
Application Scenario
Start the video stream engine to receive and render images of the cloud phone.
Prerequisites
- The video stream engine has been created and initialized.
- The logic thread has been started.
- The SurfaceView control has been initialized.
Development Process
- Record the width and height in the SurfaceView control callback function and start the connection thread.
- Call the function for starting the video stream engine in the connection thread.
Encoding Instance
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) {
// Create an activity for the first time.
newlyCreated = true;
}
@Override
public void surfaceChanged(SurfaceHolder inSurfaceHolder, int format,
int width, int height) {
if (!newlyCreated) {
return;
}
newlyCreated = false;
// The startup interface function involves socket connections. It is recommended that the function be called in a thread.
threadPool.submit(new ConnectRunable());
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
newlyCreated = false;
}
});
}
class ConnectRunable implements Runnable {
@Override
public void run() {
// Call the function for starting the video stream engine.
final int startResult = engine.start(surfaceView.getHolder().getSurface(),
guestWidth, guestHeight, metric.densityDpi);
runOnUiThread(new Runnable() {
@Override
public void run() {
if (startResult == VideoEngine.VMI_CLIENT_START_FAIL) {
// Connection failed.
} else {
// The connection is successful or has been established.
}
}
});
}
}
Parent topic: Development Process of the Video Stream Engine Client