Basic: Implementing Voice for Gaming

Basic: Implementing Voice for Gaming

Step 1: Prepare the Environment

  1. Download the Game SDK for Cocos. 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 requirements:
    • Cocos2D 3.0 or later
    • Android Studio 2.0 or later
    • Two or more Android 4.0 or later devices with audio support
  2. app_id_en

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: Obfuscate the Code

Add the following line to obfuscate the code:

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

Step 6: Call the APIs

Call the APIs in Interactive Gaming API 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 the Channel Profile (setChannelProfile).