mute
Set Audio Mute State
mute(boolean) is the core method in the SUDRTGameAudioSession interface for controlling the game sound switch. Through this method, the App can immediately cut off or restore all audio output of the mini-game engine without changing the phone's system media volume.
Method Declaration
java
/**
* Enable or disable mute mode for the game instance.
* @param var1 Pass true to mute the game; pass false to restore sound playback.
*/
void mute(boolean var1);Runtime Behavior
- Immediate Interception: After calling
mute(true), the SDK immediately stops sending data to the system's audio mixer, and the audio stream is cut off at the logical layer. - Non-persistent: This setting typically only takes effect for the currently running game handle. If the game is restarted or the handle is changed, the state usually resets to the default value (usually sound on).
- Independent Control: This method does not interfere with
setVolumeFactor(float). Even if you set the volume factor to1.0, there will still be no sound as long asmute(true)has been called. - System Decoupling: It does not trigger the Android system's "silent mode" or "Do Not Disturb mode"; it only acts within the SDK.
Code Example
Implement a UI switch logic to control the game sound on/off:
java
// Get the audio session control object
SUDRTGameAudioSession audioSession = mGameHandle.getAudioSession();
// The user clicked the "Mute" button
muteButton.setOnClickListener(v -> {
// Toggle the current state
boolean isCurrentlyMute = audioSession.isMute();
boolean newStatus = !isCurrentlyMute;
// Perform the mute/unmute operation
audioSession.mute(newStatus);
// Update the UI icon
updateMuteIcon(newStatus);
Log.d("SudAudio", "User mute operation: " + newStatus);
});Notes
- Background Behavior: It is generally recommended to use this method together with
setAudioInterruption(true)when the App moves to the background, to ensure the game does not make unexpected sounds in the background. - Physical Key Consistency: If the user lowers the volume to the minimum using the phone's physical volume keys, the system appears muted, but the logical state of
isMute()may still befalse. Note the distinction between these two. - Startup Preset: If your App enables "mute on startup" by default, call
mute(true)immediately aftergameHandle.start().
