setVolume method

Future<void> setVolume(
  1. double volumeNew
)

Sets the audio volume volume indicates a value between 0.0 (silent) and 1.0 (full volume) on a linear scale.

Implementation

Future<void> setVolume(double volumeNew) async {
  if (windows) {
    if (volumeNew <= 0) {
      volumeNew = 0;
    }
    if (volumeNew >= 1) {
      volumeNew = 1;
    }
    try {
      volume.value = volumeNew;
      showVolumeStatus.value = true;
      _videoPlayerControllerWindows!.setVolume(volumeNew);
      _timerForVolume?.cancel();
      _timerForVolume = Timer(Duration(milliseconds: 500), () {
        showVolumeStatus.value = false;
        _timerForVolume = null;
      });
    } catch (e) {
      print(e);
      throw 'Failed to get current volume';
      //return 0;
    }
  } else {
    //assert(volumeNew >= 0.0 && volumeNew <= 1.0); // validate the param
    try {
      volume.value = volumeNew;
      VolumeController().setVolume(volumeNew, showSystemUI: false);
    } catch (_) {
      print(_);
    }
  }
  //await _videoPlayerController?.setVolume(volume);
}