Skip to content

getGameAudioSession ​

Get the game audio session ​

getGameAudioSession is used to obtain the mini game's internal audio management interface. Through this interface, the host app can control the game's sound output strategy, for example handling mixing logic with other apps, force-muting, or adjusting the global volume.


Method Declaration ​

objectivec
/**
 * Get the audio session handle.
 * Used to manage the game's global audio state.
 * @return An object conforming to the SUDRTGameAudioSession protocol.
 */
- (id<SUDRTGameAudioSession>)getGameAudioSession;

Parameters ​

ParameterTypeRequiredDescription
None--This method takes no parameters.

Runtime Behavior ​

  1. Protocol interaction: The returned object conforms to the SUDRTGameAudioSession protocol, which encapsulates operations on the underlying audio engine.
  2. System integration: Operations on this handle ultimately affect the behavior of the iOS AVAudioSession (such as audio category selection and whether to respect the mute switch).
  3. Real-time effect: Volume or mute changes made through this handle take effect immediately on all background music and sound effects currently playing.

Example ​

objectivec
// 1. Get the audio session handle
id<SUDRTGameAudioSession> audioSession = [self.gameHandle getGameAudioSession];

if (audioSession) {
    // 2. Scenario: the user enabled the in-app "mute mode"
    [audioSession setMute:YES];
    
    // 3. Scenario: set the global game volume to 50%
    [audioSession setVolume:0.5f];
}

Notes ​

  • Initialization timing: It is recommended to obtain this handle after create succeeds and the instance enters the WAITING state.
  • Independence: This handle adjusts the gain inside the game engine and does not change the iOS system-level (hardware button controlled) media volume.
  • Audio conflicts: When handling incoming calls, voice chat, and similar scenarios, the app should use this handle's setMute: method to manage audio focus and avoid overlapping sound.
  • Lifecycle: This handle becomes invalid when the gameHandle is destroyed.