setVolume method

Future<void> setVolume({
  1. int? soundId,
  2. int? streamId,
  3. double? volume,
  4. double? volumeLeft,
  5. double? volumeRight,
})

Sets volume for playing sound identified by soundId or streamId

At least volume or both volumeLeft and volumeRight have to be passed

web

volumeLeft and volumeRight pair has no effect.

Implementation

Future<void> setVolume(
    {int? soundId,
    int? streamId,
    double? volume,
    double? volumeLeft,
    double? volumeRight}) async {
  assert(!_disposed, "Soundpool instance was already disposed");
  assert(
      soundId != null || streamId != null,
      "Either 'soundId' or 'streamI"
      "d' has to be passed");
  assert(
      volume != null || (volumeLeft != null && volumeRight != null),
      "Ei"
      "ther 'volume' or both 'volumeLeft' and 'volumeRight' has to be "
      "passed");

  assert(streamId == null || streamId > 0,
      "Invalid 'streamId' parameter. Only values greater than 0 are valid.");
  assert(soundId == null || soundId > -1,
      "Invalid 'soundId' parameter. Only values greater than -1 are valid.");

  if (volume != null && volumeLeft == null) {
    volumeLeft = volume;
  }
  if (volume != null && volumeRight == null) {
    volumeRight = volume;
  }
  await _soundpoolId.future.then((poolId) => _platformInstance.setVolume(
      poolId, soundId, streamId, volumeLeft, volumeRight));
}