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
- Create a DataPipe class to implement the TOUCHSENDHOOK and AUDIOSENDHOOK APIs.
- Encapsulate the DataPipe registration API and register the touch engine and audio engine.
- 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);
}
}
Parent topic: API Development Process