updateVolume() {
    /**
     * In order to fix floating math issues,
     * we set the toFixed in order to avoid 0.999999999999 increments.
     */
    let currentVolume = parseFloat(this._player.volume.toFixed(2));
    /**
     * If the volume is correctly set to the target, no need to change it
     *
     * Note: On iOS devices, volume level is totally under user's control and cannot be programmatically set.
     * We pause the music immediately in this case.
     * (https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html)
     */
    if (currentVolume === this.state.audioConfig.targetVolume || isIOS) {
      // If the audio is set to 0 and it’s been met, pause the audio
      if (this.state.audioConfig.targetVolume === 0 && this.state.pausing)
        this.pause();

      // Unmet audio volume settings require it to be changed
    } else {
      /**
       * We capture the value of the next increment by either the configuration
       * or the difference between the current and target
       * if it's smaller than the increment.
       */
      let volumeNextIncrement = Math.min(
        this.state.audioConfig.volumeSteps,
        Math.abs(this.state.audioConfig.targetVolume - this._player.volume)
      );

      /**
       * Adjust the audio based on if the target is
       * higher or lower than the current.
       */
      let volumeAdjust =
        this.state.audioConfig.targetVolume > this._player.volume
          ? volumeNextIncrement
          : -volumeNextIncrement;

      this._player.volume += volumeAdjust;

      let audioConfig = this.state.audioConfig;
      audioConfig.currentVolume += volumeAdjust;

      this.setState({
        audioConfig
      });
      // The speed at which the audio lowers is also controlled.
      setTimeout(
        this.updateVolume,
        this.state.audioConfig.volumeTransitionSpeed
      );
    }
  }
/**
   * In order to have nice fading,
   * this method adjusts the volume dynamically over time.
   */
In order to have nice fading,
this method adjusts the volume dynamically over time.
In order to have nice fading this method adjusts the volume dynamically over time .
updateVolume() {
    let currentVolume = parseFloat(this._player.volume.toFixed(2));
    if (currentVolume === this.state.audioConfig.targetVolume || isIOS) {
      if (this.state.audioConfig.targetVolume === 0 && this.state.pausing)
        this.pause();
    } else {
      let volumeNextIncrement = Math.min(
        this.state.audioConfig.volumeSteps,
        Math.abs(this.state.audioConfig.targetVolume - this._player.volume)
      );
      let volumeAdjust =
        this.state.audioConfig.targetVolume > this._player.volume
          ? volumeNextIncrement
          : -volumeNextIncrement;
      this._player.volume += volumeAdjust;
      let audioConfig = this.state.audioConfig;
      audioConfig.currentVolume += volumeAdjust;
      this.setState({
        audioConfig
      });
      setTimeout(
        this.updateVolume,
        this.state.audioConfig.volumeTransitionSpeed
      );
    }
  }
updateVolume ( ) { let currentVolume = parseFloat ( this . _player . volume . toFixed ( 2 ) ) ; if ( currentVolume === this . state . audioConfig . targetVolume || isIOS ) { if ( this . state . audioConfig . targetVolume === 0 && this . state . pausing ) this . pause ( ) ; } else { let volumeNextIncrement = Math . min ( this . state . audioConfig . volumeSteps , Math . abs ( this . state . audioConfig . targetVolume - this . _player . volume ) ) ; let volumeAdjust = this . state . audioConfig . targetVolume > this . _player . volume ? volumeNextIncrement : - volumeNextIncrement ; this . _player . volume += volumeAdjust ; let audioConfig = this . state . audioConfig ; audioConfig . currentVolume += volumeAdjust ; this . setState ( { audioConfig } ) ; setTimeout ( this . updateVolume , this . state . audioConfig . volumeTransitionSpeed ) ; } }
In order to have nice fading,
 this method adjusts the volume dynamically over time.
In order to have nice fading this method adjusts the volume dynamically over time .
/**
     * In order to fix floating math issues,
     * we set the toFixed in order to avoid 0.999999999999 increments.
     */ /**
     * If the volume is correctly set to the target, no need to change it
     *
     * Note: On iOS devices, volume level is totally under user's control and cannot be programmatically set.
     * We pause the music immediately in this case.
     * (https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html)
     */ // If the audio is set to 0 and it’s been met, pause the audio // Unmet audio volume settings require it to be changed /**
       * We capture the value of the next increment by either the configuration
       * or the difference between the current and target
       * if it's smaller than the increment.
       */ /**
       * Adjust the audio based on if the target is
       * higher or lower than the current.
       */ // The speed at which the audio lowers is also controlled.