Implementing Voice for Gaming

Step 1: Prepare the Environment

  1. Download the Game SDK for Cocos. See the following structure:

    ../_images/AMG-SDK-structure-full-Cocos2d.png
  • 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. Getting an App ID.

  3. Before accessing Agora’s services, make sure that you have opened the ports and whitelisted the domains as specified in Firewall Requirements.

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 proj.android-studio/app/build.gradle:

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

    Aternatively, use the GUI Project Structure of Android Studio:

    ../_images/Intergration-Libraries-jar-Android.png
  1. Add the .so files

    1. Add the following statement to sourceSets.main in proj.android-studio/app/build.gradle:

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

      Aternatively, use the GUI Project Structure of Android Studio:

      ../_images/Intergration-Libraries-so-Android.png
  1. Add a LOCAL_MODULE from agora-rtc, and then reference it.

    LOCAL_SHARED_LIBRARIES := agora-rtc
  1. Add the .h files. Put the following to the end of LOCAL_C_INCLUDES:
$(LOCAL_PATH)/../../../AgoraGamingSDK/include
../_images/Intergration-Libraries-h-Android.png

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

../_images/Intergration-Privileges-Android.png

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 setChannelProfile.