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

Initializing and Registering APIs of the Audio Engine and Touch Engine

Application Scenario

Initialize and register APIs of the audio engine and touch engine.

Prerequisites

An instruction stream engine object has been created.

Development Process

  1. Create a DataPipe class to implement the TOUCHSENDHOOK and AUDIOSENDHOOK APIs.
  2. Encapsulate the DataPipe registration API and register the touch engine and audio engine.
  3. When implementing TOUCHSENDHOOK and AUDIOSENDHOOK, call the APIs of the instruction stream engine for sending touch data or audio data respectively.

Encoding Instance

public class Activity implements BaseActivity {
    protected void onCreate(Bundle savedInstanceState) {
        // Set the instruction stream engine object.
        DataPipe.setInstructionEngine(engine);
        // Register the touch engine.
        DataPipe.registerHookToTouch();
        // Register the audio engine.
        DataPipe.registerAudioSendHook();
   }
}

public class DataPipe extends BaseDataPipe implements TOUCHSENDHOOK, AUDIOSENDHOOK {
    // Register the touch engine API.
    public static void registerHookToTouch() {
        // Call the touch engine registration API.
        int ret = VmiTouch.getInstance().registerTouchSendHook(DataPipe.getInstance());
        if (ret == VmiTouch.VMI_SUCCESS) {
            // The touch engine is successfully registered.
        }
    }
    // Register the audio engine API.
    public static void registerAudioSendHook() {
        // Call the audio engine registration API.
        int ret = AudioTrackPlayer.getInstance().registerAudioSendHook(DataPipe.getInstance());
        if (ret == AudioTrackPlayer.VMI_SUCCESS) {
            // The audio engine is successfully registered.
        }
    }
    @Override
    public void touchSendData(byte[] data, int length) {
        // Call the API of the instruction stream engine for sending touch data.
        instructionEngine.sendTouchEventArray(data, length);
    }
    @Override
    public void audioSendData(byte[] data, int length) {
        // Call the API for sending audio data.
        instructionEngine.sendAudioDataArray(data, length);
    }
}