getVolumeFactor
Get Volume Scaling Factor
getVolumeFactor() is a synchronous query method in the SUDRTGameAudioSession interface. It is used to get the volume ratio (scaling factor) currently output by the mini-game engine. This value determines the actual output level of the game's internal audio relative to the current system media volume.
Method Declaration
java
/**
* Get the volume scaling factor of the current game audio.
* @return float Returns a floating-point number between 0.0 and 1.0.
* 0.0 means silent (equivalent to muted), 1.0 means full output (100%).
*/
float getVolumeFactor();Runtime Behavior
- Linear Scaling: This returns a relative ratio. The final volume heard by the user =
system media volume×VolumeFactor. - Independent Control: This method allows the App to lower or raise the game's background sound independently without changing the phone's physical volume buttons.
- Real-time State: If
setVolumeFactor(0.5f)was previously called, this method will immediately return0.5.
Code Example
Sync the value when initializing the App's volume control slider:
java
// 1. Get the audio session from the game handle
SUDRTGameAudioSession audioSession = mGameHandle.getAudioSession();
// 2. Get the current volume factor (e.g., 0.8f)
float currentFactor = audioSession.getVolumeFactor();
// 3. Map it to the progress bar (assuming the range is 0-100)
int progress = (int)(currentFactor * 100);
volumeSeekBar.setProgress(progress);
Log.d("SudAudio", "Current game volume percentage: " + progress + "%");Notes
- Difference from System Volume: If the phone's system volume itself is set to 0, the user will still hear nothing even if
getVolumeFactor()returns1.0. - Relationship with Mute State:
getVolumeFactor()returning0.0is equivalent in effect toisMute()returningtrue, but they are two independent logical control bits. - Precision Recommendation: Although a
floatis returned, it is generally recommended that the App side map it to a percentage (0-100) for UI display, to match users' operating habits.
