# VolumeShaper.Configuration.Builder

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/media/VolumeShaper.Configuration.Builder "View this page in Java")  

```
class Builder
```

|---|------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                       ||
| ↳ | [android.media.VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) |

Builder class for a[VolumeShaper.Configuration](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration)object.

Here is an example where`Builder`is used to define the[VolumeShaper.Configuration](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration).  

```kotlin
VolumeShaper.Configuration LINEAR_RAMP =
          new VolumeShaper.Configuration.Builder()
              .setInterpolatorType(VolumeShaper.Configuration.INTERPOLATOR_TYPE_LINEAR)
              .setCurve(new float[] { 0.f, 1.f }, // times
                        new float[] { 0.f, 1.f }) // volumes
              .setDuration(1000)
              .build();
  
```

<br />

## Summary

|                                                                                                                                                                                         Public constructors                                                                                                                                                                                         ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#Builder())`()` Constructs a new`Builder`with the defaults.                                                                                                                                                                                                                             |
| [Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#Builder(android.media.VolumeShaper.Configuration))`(`configuration:` `[VolumeShaper.Configuration](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration)`)` Constructs a new`Builder`with settings copied from a given`VolumeShaper.Configuration`. |

|                                                                                                                                                                                                                                                               Public methods                                                                                                                                                                                                                                                                ||
|----------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [VolumeShaper.Configuration](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration)                  | [build](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#build())`()` Builds a new[VolumeShaper](https://developer.android.com/reference/kotlin/android/media/VolumeShaper)object.                                                                                                                                                                   |
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | [invertVolumes](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#invertVolumes())`()` Inverts the volume curve so that the max volume becomes the min volume and vice versa.                                                                                                                                                                         |
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | [reflectTimes](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#reflectTimes())`()` Reflects the volume curve so that the shaper changes volume from the end to the start.                                                                                                                                                                           |
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | [scaleToEndVolume](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#scaleToEndVolume(kotlin.Float))`(`volume:` `[Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html)`)` Scale the curve end volume to a target value.                                                                                                      |
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | [scaleToStartVolume](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#scaleToStartVolume(kotlin.Float))`(`volume:` `[Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html)`)` Scale the curve start volume to a target value.                                                                                                |
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | [setCurve](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#setCurve(kotlin.FloatArray,%20kotlin.FloatArray))`(`times:` `[FloatArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float-array/index.html)`, `volumes:` `[FloatArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float-array/index.html)`)` Sets the volume curve. |
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | [setDuration](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#setDuration(kotlin.Long))`(`durationMillis:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Sets the`VolumeShaper`duration in milliseconds.                                                                                                         |
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | [setInterpolatorType](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#setInterpolatorType(kotlin.Int))`(`interpolatorType:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets the interpolator type.                                                                                                              |

## Public constructors

### Builder

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder()
```

Constructs a new`Builder`with the defaults.  

### Builder

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder(configuration: VolumeShaper.Configuration)
```

Constructs a new`Builder`with settings copied from a given`VolumeShaper.Configuration`.

|                                                                                                               Parameters                                                                                                                ||
|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `configuration` | [VolumeShaper.Configuration](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration):prototypical configuration which will be reused in the new`Builder`. This value cannot be`null`. |

## Public methods

### build

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun build(): VolumeShaper.Configuration
```

Builds a new[VolumeShaper](https://developer.android.com/reference/kotlin/android/media/VolumeShaper)object.

|                                                                                                                          Return                                                                                                                          ||
|-----------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|
| [VolumeShaper.Configuration](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration) | a new[VolumeShaper](https://developer.android.com/reference/kotlin/android/media/VolumeShaper)object. This value cannot be`null`. |

|                            Exceptions                            ||
|-----------------------------------|-------------------------------|
| `java.lang.IllegalStateException` | if curve is not properly set. |

### invertVolumes

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun invertVolumes(): VolumeShaper.Configuration.Builder
```

Inverts the volume curve so that the max volume becomes the min volume and vice versa.

|                                                                                             Return                                                                                             ||
|----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | the same`Builder`instance. This value cannot be`null`. |

|                          Exceptions                           ||
|-----------------------------------|----------------------------|
| `java.lang.IllegalStateException` | if curve has not been set. |

### reflectTimes

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun reflectTimes(): VolumeShaper.Configuration.Builder
```

Reflects the volume curve so that the shaper changes volume from the end to the start.

|                                                                                             Return                                                                                             ||
|----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | the same`Builder`instance. This value cannot be`null`. |

|                          Exceptions                           ||
|-----------------------------------|----------------------------|
| `java.lang.IllegalStateException` | if curve has not been set. |

### scaleToEndVolume

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun scaleToEndVolume(volume: Float): VolumeShaper.Configuration.Builder
```

Scale the curve end volume to a target value. Keeps the start volume the same. This works best if the volume curve is monotonic.

|                                                       Parameters                                                       ||
|----------|--------------------------------------------------------------------------------------------------------------|
| `volume` | [Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html):the target end volume to use. |

|                                                                                             Return                                                                                             ||
|----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | the same`Builder`instance. This value cannot be`null`. |

|                            Exceptions                            ||
|--------------------------------------|----------------------------|
| `java.lang.IllegalArgumentException` | if`volume`is not valid.    |
| `java.lang.IllegalStateException`    | if curve has not been set. |

### scaleToStartVolume

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun scaleToStartVolume(volume: Float): VolumeShaper.Configuration.Builder
```

Scale the curve start volume to a target value. Keeps the end volume the same. This works best if the volume curve is monotonic.

|                                                        Parameters                                                        ||
|----------|----------------------------------------------------------------------------------------------------------------|
| `volume` | [Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html):the target start volume to use. |

|                                                                                             Return                                                                                             ||
|----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | the same`Builder`instance. This value cannot be`null`. |

|                            Exceptions                            ||
|--------------------------------------|----------------------------|
| `java.lang.IllegalArgumentException` | if`volume`is not valid.    |
| `java.lang.IllegalStateException`    | if curve has not been set. |

### setCurve

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setCurve(
    times: FloatArray, 
    volumes: FloatArray
): VolumeShaper.Configuration.Builder
```

Sets the volume curve. The volume curve is represented by a set of control points given by two float arrays of equal length, one representing the time (x) coordinates and one corresponding to the volume (y) coordinates. The length must be at least 2 and no greater than[VolumeShaper.Configuration.getMaximumCurvePoints()](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration#getMaximumCurvePoints()).

The volume curve is normalized as follows: time (x) coordinates should be monotonically increasing, from 0.f to 1.f; volume (y) coordinates must be within 0.f to 1.f.

The time scale is set by[setDuration](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#setDuration(kotlin.Long)).

<br />

|                                                                                                Parameters                                                                                                 ||
|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `times`   | [FloatArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float-array/index.html):an array of float values representing the time line of the volume curve. This value cannot be`null`. |
| `volumes` | [FloatArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float-array/index.html):an array of float values representing the amplitude of the volume curve. This value cannot be`null`. |

|                                                                                             Return                                                                                             ||
|----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | the same`Builder`instance. This value cannot be`null`. |

|                              Exceptions                               ||
|--------------------------------------|---------------------------------|
| `java.lang.IllegalArgumentException` | if`times`or`volumes`is invalid. |

### setDuration

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setDuration(durationMillis: Long): VolumeShaper.Configuration.Builder
```

Sets the`VolumeShaper`duration in milliseconds. If omitted, the default duration is 1 second.

|                                           Parameters                                            ||
|------------------|-------------------------------------------------------------------------------|
| `durationMillis` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html): |

|                                                                                             Return                                                                                             ||
|----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | the same`Builder`instance. This value cannot be`null`. |

|                                    Exceptions                                     ||
|--------------------------------------|---------------------------------------------|
| `java.lang.IllegalArgumentException` | if`durationMillis`is not strictly positive. |

### setInterpolatorType

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setInterpolatorType(interpolatorType: Int): VolumeShaper.Configuration.Builder
```

Sets the interpolator type. If omitted the default interpolator type is[INTERPOLATOR_TYPE_CUBIC](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration#INTERPOLATOR_TYPE_CUBIC:kotlin.Int).

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ||
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `interpolatorType` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):method of interpolation used for the volume curve. One of[INTERPOLATOR_TYPE_STEP](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration#INTERPOLATOR_TYPE_STEP:kotlin.Int),[INTERPOLATOR_TYPE_LINEAR](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration#INTERPOLATOR_TYPE_LINEAR:kotlin.Int),[INTERPOLATOR_TYPE_CUBIC](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration#INTERPOLATOR_TYPE_CUBIC:kotlin.Int),[INTERPOLATOR_TYPE_CUBIC_MONOTONIC](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration#INTERPOLATOR_TYPE_CUBIC_MONOTONIC:kotlin.Int). Value is[android.media.VolumeShaper.Configuration#INTERPOLATOR_TYPE_STEP](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration#INTERPOLATOR_TYPE_STEP:kotlin.Int),[android.media.VolumeShaper.Configuration#INTERPOLATOR_TYPE_LINEAR](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration#INTERPOLATOR_TYPE_LINEAR:kotlin.Int),[android.media.VolumeShaper.Configuration#INTERPOLATOR_TYPE_CUBIC](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration#INTERPOLATOR_TYPE_CUBIC:kotlin.Int), or[android.media.VolumeShaper.Configuration#INTERPOLATOR_TYPE_CUBIC_MONOTONIC](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration#INTERPOLATOR_TYPE_CUBIC_MONOTONIC:kotlin.Int) |

|                                                                                             Return                                                                                             ||
|----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| [VolumeShaper.Configuration.Builder](https://developer.android.com/reference/kotlin/android/media/VolumeShaper.Configuration.Builder#) | the same`Builder`instance. This value cannot be`null`. |

|                               Exceptions                                ||
|--------------------------------------|-----------------------------------|
| `java.lang.IllegalArgumentException` | if`interpolatorType`is not valid. |