目录

Sample Code

The following example shows how to use the headset monitoring feature for karaoke scenarios.

Name

Download Package

Find It on GitHub

Android Studio sample code

huawei-audioEngine-android-demo.zip

-

Creating and Initializing an Object, and Registering a Callback

mHwAudioKit = new HwAudioKit(this, callBack);
mHwAudioKit.initialize();
// Create the KaraokeFeature object:
mHwAudioKaraokeFeatureKit = mHwAudioKit.createFeature(HwAudioKit.FeatureType. HWAUDIO_FEATURE_KARAOKE);
// Create a callback.
IAudioKitCallback callBack = new IAudioKitCallback() {
@Override
public void onResult(int i) {
if (i == 0) {
// HwAudioKit initialization is successful. Its APIs can be used, such as:
mHwAudioKit .getSupportedFeatures(); // Return the list set.
mHwAudioKit .isFeatureSupported(FeatureType type); // Return true or false: true indicates that the product supports the query function, while false indicates not.
}
if (i == 2) {
// The engine service is not installed, and the engine is not supported.
}
if (i == 1000) {
// HwAudioKaraokeFeatureKit initialization is successful. Its APIs can be used, such as:
// Query whether the headset monitoring feature is supported: true indicates supported, while false indicates not.
int isSupport = mHwAudioKaraokeFeatureKit.isKaraokeFeatureSupport();
// Turn on or off the headset monitoring feature. The value 0 indicates success, 1806 indicates that the product does not support the headset monitoring feature, and 1805 indicates that no headset is inserted.
boolean   = mHwAudioKaraokeFeatureKit.enableKaraokeFeature(enable);
// Set the sound effect and volume. The value 0 indicates success, 1806 indicates that the product does not support the headset monitoring feature, 1805 indicates that no headset is inserted, and 1807 indicates a parameter error.
int success = mHwAudioKaraokeFeatureKit.setParameter(HwAudioKaraokeFeatureKit.ParameName.CMD_SET_AUDIO_EFFECT_MODE_BASE, value);
// Obtain the latency information. The value -1 indicates an obtaining failure.
int latency = mHwAudioKaraokeFeatureKit.getKaraokeLatency();
  }
 }
}

Destroying the Feature

mHwAudioKaraokeFeatureKit.destroy();
mHwAudioKit.destroy();