Implementing Voice for Gaming

Implementing Voice for Gaming

Step 1: Prepare the Environment

  1. Download the latest Cocos2d kit. See the following structure:

  • include: header files. Used in Cocos2d projects when modifying raw data.
  • libs: library files. Only .jar and .so files in the Android folder are used on this page.
  • samples: sample code.
  1. Hardware and software prerequisites:
    • Android Studio 2.0 or later
    • Android 4.0 or later devices with audio functions
    • Get an App ID

Step 2: Create a New Project

Create a new Cocos2d project. Refer to here if necessary. Skip this step if a project already exists.

Step 3: Add the SDK

  1. Create a new folder, such as AgoraGamingSDK, under the root directory of the project.

  2. Copy the include and libs folders to AgoraGamingSDK.

  3. Add .jar files. Add the following statement to dependencies in

    compile fileTree(include: ['*.jar'], dir: '../../AgoraGamingSDK/libs/Android')

    Aternatively, use the GUI Project Structure of Android Studio:

  4. Add the .so files

    1. Add the following statement to sourceSets.main in

      jniLibs.srcDirs = ["libs", "../../AgoraGamingSDK/libs/Android"]

      Aternatively, use the GUI Project Structure of Android Studio:

  1. Add a LOCAL_MODULE from agora-rtc, and then reference it.

  1. Add the .h files. Put the following to the end of LOCAL_C_INCLUDES:

Step 4: Add Permissions

Add the necessary permissions, such as:

  • android.permission.INTERNET
  • android.permission.RECORD_AUDIO
  • android.permission.MODIFY_AUDIO_SETTINGS
  • android.permission.ACCESS_NETWORK_STATE
  • android.permission.BLUETOOTH

Step 5: Obfuscated Code

Add the following to obfuscate code:

-keep class io.agora.**{*;}

Step 6: Call the APIs

As specified in Interactive Gaming API, call the APIs to implement the required functions. Voice for gaming includes two modes:

  • Free talk mode
  • Command mode

You can choose which mode to use by calling Set Channel Profile (setChannelProfile).