setAppVolume static method
If your app has its own volume controls (such as custom music or sound effect volumes), disclosing app volume to the Google Mobile Ads SDK allows video ads to respect app volume settings. This ensures users receive video ads with the expected audio volume.
The device volume, controlled through volume buttons or OS-level volume slider, determines
the volume for device audio output. However, apps can independently adjust volume levels
relative to the device volume to tailor the audio experience. You can report the relative
app volume to the Mobile Ads SDK through the static setAppVolume()
method. Valid ad volume
values range from 0.0 (silent) to 1.0 (current device volume). Here's an example of how to
report the relative app volume to the SDK:
MobileAds.initialize();
// Set app volume to be half of current device volume.
MobileAds.setAppVolume(0.5);
Implementation
static Future<void> setAppVolume(double volume) {
assert(
volume >= 0 && volume <= 1,
'The volume must be in bettwen of 0 and 1',
);
return _pluginChannel.invokeMethod('setAppVolume', {'volume': volume});
}