setVolume method

Future<void> setVolume(
  1. double volume
)

Implementation

Future<void> setVolume(double volume) async {
  if (!_undisposedAudios.containsKey(_audioId)) {
    _logger.severe('Called set volume on a disposed Audio');
    return;
  }
  if (volume < 0.0 || volume > 1.0) {
    _logger.warning(
        'Invalid volume value $volume is begin clamped to 0.0 to 1.0.');
    volume.clamp(0.0, 1.0);
  }

  _volume = volume;

  try {
    await _sendMethodCall(_audioId, setVolumeMethod,
        <String, dynamic>{audioIdKey: _audioId, volumeKey: volume});
  } on PlatformException catch (e) {
    if (_usingOnErrorAudios.containsKey(_audioId)) {
      // Audio has an onError callback.
      _usingOnErrorAudios[_audioId]!._onError!(e.message);
    } else {
      // Audio does not use an onError callback: rethrow the exception.
      rethrow;
    }
  }
}