setAudioSessionStartOptions
Set Audio Session Start Options
setAudioSessionStartOptions is the method in the SUDRTGameAudioSession interface for deeply customizing the audio engine's initialization behavior. It allows the App to pass underlying parameters such as Performance Mode and Session ID via a Bundle before the game audio stream is formally established, to optimize audio latency or power consumption on Android devices.
Method Declaration
java
/**
* Configure audio session start parameters.
* @param var1 A Bundle containing the start configuration items. Common keys include:
* - KEY_AUDIO_START_OPTION_PERFORMANCE_MODE
* - KEY_AUDIO_START_OPTION_SESSION_ID
* @return boolean Whether the configuration succeeded. Returns true if the parameters have been recorded and will take effect at the next audio initialization.
*/
boolean setAudioSessionStartOptions(Bundle var1);Core Configuration Items and Constants
Setting the following parameters via the Bundle can significantly change audio behavior:
1. Performance Mode
Determines the system's strategy for handling the audio buffer.
| Constant Value | Description | Use Cases |
|---|---|---|
| VALUE_PERFORMANCE_MODE_LOW_LATENCY | Low-latency mode: fastest response, smallest buffer. | Competitive games, rhythm games, real-time battles. |
| VALUE_PERFORMANCE_MODE_POWER_SAVING | Power-saving mode: increases latency in exchange for lower CPU usage. | Casual mini-games, idle games. |
| VALUE_PERFORMANCE_MODE_NONE | Default mode: balances performance and compatibility. | Regular game scenarios. |
2. Session ID
Used to associate the game audio with a specific Android AudioSession.
- VALUE_SESSION_ID_ALLOCATE: The SDK automatically allocates a new ID, making it easier to apply system-level audio effects (such as an equalizer) later.
- VALUE_SESSION_ID_NONE: Do not associate with a specific session.
Code Example
Configure a low-latency environment before game startup or audio reset:
java
// Get the audio session object
SUDRTGameAudioSession audioSession = mGameHandle.getAudioSession();
// 1. Prepare the start configuration
Bundle options = new Bundle();
// Set to low-latency mode to optimize the game experience
options.putInt(SUDRTGameAudioSession.KEY_AUDIO_START_OPTION_PERFORMANCE_MODE,
SUDRTGameAudioSession.VALUE_PERFORMANCE_MODE_LOW_LATENCY);
// Request the SDK to allocate an independent Session ID
options.putInt(SUDRTGameAudioSession.KEY_AUDIO_START_OPTION_SESSION_ID,
SUDRTGameAudioSession.VALUE_SESSION_ID_ALLOCATE);
// 2. Apply the configuration
boolean isSuccess = audioSession.setAudioSessionStartOptions(options);
if (isSuccess) {
Log.d("SudAudio", "Audio start parameters configured successfully, waiting for the engine to load...");
}Notes
- Timing: This method must be called before the audio engine initializes (usually
gameHandle.start()or the audio stream is established). If the audio has already started playing, the setting may not take effect immediately until the next audio stream rebuild. - Hardware Limitations: The effect of
LOW_LATENCYmode depends on the hardware support of the Android device. On some low-end devices, enabling this mode may not produce a noticeable difference. - Power Trade-off: Low-latency mode usually means more frequent CPU wake-ups. If players are very sensitive to battery life, it is recommended to use
POWER_SAVINGmode in non-core match scenarios.
