Skip to content

mute ​

Set Mute State ​

mute: is the audio switch method of the SUDRTGameAudioSession protocol. It is used to immediately enable or disable all audio output of the current game instance at the software level. This method provides a global "one-tap mute" feature, commonly used when the App switches to the background, the user enables Do Not Disturb mode, or specific business logic (such as answering a phone call) is triggered.


Method Declaration ​

objc
/**
 * Sets game audio to muted or resumes playback.
 * @param mute YES indicates immediate mute; NO indicates resuming playback at the previous volume.
 */
- (void)mute:(BOOL)mute;

Runtime Behavior ​

  1. Global interception: When the parameter is YES, the SDK cuts off the output of all game audio tracks. This does not affect the game logic's execution; it only blocks the audio stream from reaching the system mixer.
  2. Volume retention: Calling mute:YES does not modify the value of VolumeFactor. When mute:NO is called again to restore sound, the game volume automatically returns to the scaling ratio before muting.
  3. State isolation: This mute switch is effective only for the current SDK instance and does not affect the sound playback of other Apps in the iOS system (AVAudioSession).
  4. Non-persistence: This state typically becomes invalid when the game instance is destroyed. If you want the player to remain muted the next time they enter the game, the App side needs to record this configuration itself.

Code Example ​

Automatically mute the game when the App detects an incoming system call:

objc
- (void)handleIncomingCall {
    // 1. When the business logic is triggered, immediately mute the game
    if (![self.audioSession isMute]) {
        [self.audioSession mute:YES];
        NSLog(@"External interference detected, game auto-muted");
    }
}

- (void)onMuteToggleChanged:(UISwitch *)sender {
    // 2. Set mute based on the UI switch state
    [self.audioSession mute:sender.isOn];
}

Notes ​

  • Difference from hardware mute: This method controls "software mute". If the user enables muting via the physical mute switch on the side of the iPhone, the game may still be silent even if mute:NO is called (depending on the SUDRT_KEY_AUDIO_OBEY_MUTE_SWITCH configuration).
  • Performance recommendation: Calling mute: frequently in a short period may cause the underlying audio pipeline to be repeatedly initialized. It is recommended to add debouncing at the UI layer.
  • State query: Before executing logic, you can first determine the current state via the isMute method to avoid redundantly setting the same state.