# QualitySelector

Artifact: [androidx.camera:camera-video](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/video/QualitySelector.java+class:androidx.camera.video.QualitySelector) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

*** ** * ** ***


```
public final class QualitySelector
```

<br />

*** ** * ** ***

QualitySelector defines a desired quality setting that can be used to configure components with quality setting requirements such as creating a `https://developer.android.com/reference/androidx/camera/video/Recorder.Builder#setQualitySelector(androidx.camera.video.QualitySelector)`.

There are pre-defined quality constants that are universally used for video, such as `https://developer.android.com/reference/androidx/camera/video/Quality#SD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#FHD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#QHD()` and `https://developer.android.com/reference/androidx/camera/video/Quality#UHD()`, but not all of them are supported on every device since each device has its own capabilities. `https://developer.android.com/reference/androidx/camera/video/QualitySelector#isQualitySupported(androidx.camera.core.CameraInfo,androidx.camera.video.Quality)` can be used to check whether a quality is supported on the device or not and `https://developer.android.com/reference/androidx/camera/video/QualitySelector#getResolution(androidx.camera.core.CameraInfo,androidx.camera.video.Quality)` can be used to get the actual resolution defined in the device. Aside from checking the qualities one by one, QualitySelector provides a more convenient way to select a quality. The typical usage of selecting a single desired quality is:

```
  QualitySelector qualitySelector = QualitySelector.from(Quality.FHD);
```
or the usage of selecting a series of qualities by desired order:

```
  QualitySelector qualitySelector = QualitySelector.fromOrderedList(
          Arrays.asList(Quality.FHD, Quality.HD, Quality.HIGHEST)
  );
```
The recommended way is giving a guaranteed supported quality such as `https://developer.android.com/reference/androidx/camera/video/Quality#LOWEST()` or `https://developer.android.com/reference/androidx/camera/video/Quality#HIGHEST()` in the end of the desired quality list, which ensures the QualitySelector can always choose a supported quality. Another way to ensure a quality will be selected when none of the desired qualities are supported is to use `https://developer.android.com/reference/androidx/camera/video/QualitySelector#fromOrderedList(java.util.List<androidx.camera.video.Quality>,androidx.camera.video.FallbackStrategy)` with an open-ended fallback strategy such as a fallback strategy from `https://developer.android.com/reference/androidx/camera/video/FallbackStrategy#lowerQualityOrHigherThan(androidx.camera.video.Quality)`:

```
  QualitySelector qualitySelector = QualitySelector.fromOrderedList(
          Arrays.asList(Quality.UHD, Quality.FHD),
          FallbackStrategy.lowerQualityOrHigherThan(Quality.FHD)
  );
```
If UHD and FHD are not supported on the device, QualitySelector will select the quality that is closest to and lower than FHD. If no lower quality is supported, the quality that is closest to and higher than FHD will be selected.

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/QualitySelector` | `https://developer.android.com/reference/androidx/camera/video/QualitySelector#from(androidx.camera.video.Quality)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/Quality quality)` Gets an instance of QualitySelector with a desired quality. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/QualitySelector` | `https://developer.android.com/reference/androidx/camera/video/QualitySelector#from(androidx.camera.video.Quality,androidx.camera.video.FallbackStrategy)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/Quality quality, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/FallbackStrategy fallbackStrategy)` Gets an instance of QualitySelector with a desired quality and a fallback strategy. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/QualitySelector` | `https://developer.android.com/reference/androidx/camera/video/QualitySelector#fromOrderedList(java.util.List<androidx.camera.video.Quality>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/video/Quality> qualities)` Gets an instance of QualitySelector with ordered desired qualities. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/QualitySelector` | `https://developer.android.com/reference/androidx/camera/video/QualitySelector#fromOrderedList(java.util.List<androidx.camera.video.Quality>,androidx.camera.video.FallbackStrategy)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/video/Quality> qualities, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/FallbackStrategy fallbackStrategy )` Gets an instance of QualitySelector with ordered desired qualities and a fallback strategy. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/util/Size.html` | `https://developer.android.com/reference/androidx/camera/video/QualitySelector#getResolution(androidx.camera.core.CameraInfo,androidx.camera.video.Quality)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraInfo cameraInfo, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/Quality quality)` Gets the corresponding resolution from the input quality. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/video/Quality>` | `[getSupportedQualities](https://developer.android.com/reference/androidx/camera/video/QualitySelector#getSupportedQualities(androidx.camera.core.CameraInfo))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraInfo cameraInfo)` **This method is deprecated.** use `https://developer.android.com/reference/androidx/camera/video/VideoCapabilities#getSupportedQualities(androidx.camera.core.DynamicRange)` instead. <br /> |
| `static boolean` | `[isQualitySupported](https://developer.android.com/reference/androidx/camera/video/QualitySelector#isQualitySupported(androidx.camera.core.CameraInfo,androidx.camera.video.Quality))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraInfo cameraInfo, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/Quality quality )` **This method is deprecated.** use `https://developer.android.com/reference/androidx/camera/video/VideoCapabilities#isQualitySupported(androidx.camera.video.Quality,androidx.camera.core.DynamicRange)` instead. <br /> |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/camera/video/QualitySelector#toString()()` |

## Public methods

### from

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public static @NonNull QualitySelector from(@NonNull Quality quality)
```

Gets an instance of QualitySelector with a desired quality.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/Quality quality` | the quality. Possible values include `https://developer.android.com/reference/androidx/camera/video/Quality#LOWEST()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HIGHEST()`, `https://developer.android.com/reference/androidx/camera/video/Quality#SD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#FHD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#QHD()`, or `https://developer.android.com/reference/androidx/camera/video/Quality#UHD()`. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/QualitySelector` | the QualitySelector instance. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `quality` is `null`. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `quality` is not one of the possible values. |

### from

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public static @NonNull QualitySelector from(@NonNull Quality quality, @NonNull FallbackStrategy fallbackStrategy)
```

Gets an instance of QualitySelector with a desired quality and a fallback strategy.

If the quality is not supported, the fallback strategy will be applied. The fallback strategy can be created by `https://developer.android.com/reference/androidx/camera/video/FallbackStrategy` API such as `https://developer.android.com/reference/androidx/camera/video/FallbackStrategy#lowerQualityThan(androidx.camera.video.Quality)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/Quality quality` | the quality. Possible values include `https://developer.android.com/reference/androidx/camera/video/Quality#LOWEST()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HIGHEST()`, `https://developer.android.com/reference/androidx/camera/video/Quality#SD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#FHD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#QHD()`, or `https://developer.android.com/reference/androidx/camera/video/Quality#UHD()`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/FallbackStrategy fallbackStrategy` | the fallback strategy that will be applied when the device does not support `quality`. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/QualitySelector` | the QualitySelector instance. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `quality` is `null` or `fallbackStrategy` is `null`. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `quality` is not one of the possible values. |

### fromOrderedList

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public static @NonNull QualitySelector fromOrderedList(@NonNull List<Quality> qualities)
```

Gets an instance of QualitySelector with ordered desired qualities.

The final quality will be selected according to the order in the quality list.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/video/Quality> qualities` | the quality list. Possible values include `https://developer.android.com/reference/androidx/camera/video/Quality#LOWEST()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HIGHEST()`, `https://developer.android.com/reference/androidx/camera/video/Quality#SD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#FHD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#QHD()`, or `https://developer.android.com/reference/androidx/camera/video/Quality#UHD()`. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/QualitySelector` | the QualitySelector instance. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `qualities` is `null`. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `qualities` is empty or contains a quality that is not one of the possible values, including a `null` value. |

### fromOrderedList

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public static @NonNull QualitySelector fromOrderedList(
    @NonNull List<Quality> qualities,
    @NonNull FallbackStrategy fallbackStrategy
)
```

Gets an instance of QualitySelector with ordered desired qualities and a fallback strategy.

The final quality will be selected according to the order in the quality list. If no quality is supported, the fallback strategy will be applied. The fallback strategy can be created by `https://developer.android.com/reference/androidx/camera/video/FallbackStrategy` API such as `https://developer.android.com/reference/androidx/camera/video/FallbackStrategy#lowerQualityThan(androidx.camera.video.Quality)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/video/Quality> qualities` | the quality list. Possible values include `https://developer.android.com/reference/androidx/camera/video/Quality#LOWEST()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HIGHEST()`, `https://developer.android.com/reference/androidx/camera/video/Quality#SD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#FHD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#QHD()`, or `https://developer.android.com/reference/androidx/camera/video/Quality#UHD()`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/FallbackStrategy fallbackStrategy` | the fallback strategy that will be applied when the device does not support those `qualities`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `qualities` is `null` or `fallbackStrategy` is `null`. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `qualities` is empty or contains a quality that is not one of the possible values, including a `null` value. |

### getResolution

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public static @Nullable Size getResolution(@NonNull CameraInfo cameraInfo, @NonNull Quality quality)
```

Gets the corresponding resolution from the input quality.

Possible values for `quality` include `https://developer.android.com/reference/androidx/camera/video/Quality#LOWEST()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HIGHEST()`, `https://developer.android.com/reference/androidx/camera/video/Quality#SD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#FHD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#QHD()` and `https://developer.android.com/reference/androidx/camera/video/Quality#UHD()`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraInfo cameraInfo` | the cameraInfo for checking the quality. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/Quality quality` | one of the quality constants. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/util/Size.html` | the corresponding resolution from the input quality, or `null` if the quality is not supported on the device. `https://developer.android.com/reference/androidx/camera/video/QualitySelector#isQualitySupported(androidx.camera.core.CameraInfo,androidx.camera.video.Quality)` can be used to check if the input quality is supported. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if quality is not one of the possible values. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/camera/video/QualitySelector#isQualitySupported(androidx.camera.core.CameraInfo,androidx.camera.video.Quality)` |   |

### getSupportedQualities

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0) Deprecated in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
public static @NonNull List<Quality> [getSupportedQualities](https://developer.android.com/reference/androidx/camera/video/QualitySelector#getSupportedQualities(androidx.camera.core.CameraInfo))(@NonNull CameraInfo cameraInfo)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> use `https://developer.android.com/reference/androidx/camera/video/VideoCapabilities#getSupportedQualities(androidx.camera.core.DynamicRange)` instead.

Gets all supported qualities on the device.

The returned list is sorted by quality size from largest to smallest. For the qualities in the returned list, with the same input cameraInfo, `https://developer.android.com/reference/androidx/camera/video/QualitySelector#isQualitySupported(androidx.camera.core.CameraInfo,androidx.camera.video.Quality)` will return `true` and `https://developer.android.com/reference/androidx/camera/video/QualitySelector#getResolution(androidx.camera.core.CameraInfo,androidx.camera.video.Quality)` will return the corresponding resolution.

Note: Constants `https://developer.android.com/reference/androidx/camera/video/Quality#HIGHEST()` and `https://developer.android.com/reference/androidx/camera/video/Quality#LOWEST()` are not included in the returned list, but their corresponding qualities are included.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraInfo cameraInfo` | the cameraInfo |

### isQualitySupported

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0) Deprecated in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
public static boolean [isQualitySupported](https://developer.android.com/reference/androidx/camera/video/QualitySelector#isQualitySupported(androidx.camera.core.CameraInfo,androidx.camera.video.Quality))(
    @NonNull CameraInfo cameraInfo,
    @NonNull Quality quality
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> use `https://developer.android.com/reference/androidx/camera/video/VideoCapabilities#isQualitySupported(androidx.camera.video.Quality,androidx.camera.core.DynamicRange)` instead.

Checks if the quality is supported.

Calling this method with one of the qualities contained in the returned list of `https://developer.android.com/reference/androidx/camera/video/QualitySelector#getSupportedQualities(androidx.camera.core.CameraInfo)` will return `true`.

Possible values for `quality` include `https://developer.android.com/reference/androidx/camera/video/Quality#LOWEST()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HIGHEST()`, `https://developer.android.com/reference/androidx/camera/video/Quality#SD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#HD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#FHD()`, `https://developer.android.com/reference/androidx/camera/video/Quality#QHD()` and `https://developer.android.com/reference/androidx/camera/video/Quality#UHD()`.

If this method is called with `https://developer.android.com/reference/androidx/camera/video/Quality#LOWEST()` or `https://developer.android.com/reference/androidx/camera/video/Quality#HIGHEST()`, it will return `true` except the case that none of the qualities can be supported.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraInfo cameraInfo` | the cameraInfo for checking the quality. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/Quality quality` | one of the quality constants. |

| Returns |
|---|---|
| `boolean` | `true` if the quality is supported; `false` otherwise. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/camera/video/QualitySelector#getSupportedQualities(androidx.camera.core.CameraInfo)` |   |

### toString

```
public @NonNull String toString()
```