我要评分
获取效率
正确性
完整性
易理解

Developing the Screen Rotation Function

Application Scenario

Switch between landscape and portrait modes on the client.

Prerequisites

The video stream engine is started successfully.

Development Process

Process the screen rotation function using the orientationCallback function.

Encoding Instance

public void onVmiEngineEvent (int event, int reserved0, int reserved1, int reserved2, int reserved3, String additionInfo) {
    if (event == VideoEngine.VMI_ENGINE_EVENT_ORIENTATION_CHANGED) {
        engineOrientation = reserved0;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
               setRotation(engineOrientation);
            }
         });
    }
}

private void setRotation(int rotation) {
        final int rota = rotation;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (oritentation != rota) {
                    oritentation = rota;
                    switch (oritentation) {
                        case Surface.ROTATION_0:
                            // Rotate the SurfaceView UI.
                            surfaceView.setScreenRotation(VideoEngine.Rotation.ROTATION0);
                            // Set the screen orientation.
                            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                            break;
                        case Surface.ROTATION_90:
                            surfaceView.setScreenRotation(VideoEngine.Rotation.ROTATION90);
                            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

                            break;
                        case Surface.ROTATION_180:
                            surfaceView.setScreenRotation(VideoEngine.Rotation.ROTATION180);
                            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                            break;
                        case Surface.ROTATION_270:
                            surfaceView.setScreenRotation(VideoEngine.Rotation.ROTATION270);
                            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                            break;
                        default:
                            break;
                    }
                }
            }
        });
    }