QualitySelector

public final class QualitySelector
extends Object

java.lang.Object
   ↳ androidx.camera.video.QualitySelector


QualitySelector defines a desired quality setting that can be used to configure components with quality setting requirements such as creating a Recorder.

There are pre-defined quality constants that are universally used for video, such as Quality.SD, Quality.HD, Quality.FHD and Quality.UHD, but not all of them are supported on every device since each device has its own capabilities. isQualitySupported(CameraInfo, Quality) can be used to check whether a quality is supported on the device or not and getResolution(CameraInfo, 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 Quality.LOWEST or 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 fromOrderedList(List, FallbackStrategy) with an open-ended fallback strategy such as a fallback strategy from FallbackStrategy.lowerQualityOrHigherThan(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 QualitySelector from(Quality quality)

Gets an instance of QualitySelector with a desired quality.

static QualitySelector from(Quality quality, FallbackStrategy fallbackStrategy)

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

static QualitySelector fromOrderedList(List<Quality> qualities)

Gets an instance of QualitySelector with ordered desired qualities.

static QualitySelector fromOrderedList(List<Quality> qualities, FallbackStrategy fallbackStrategy)

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

static Size getResolution(CameraInfo cameraInfo, Quality quality)

Gets the corresponding resolution from the input quality.

static List<Quality> getSupportedQualities(CameraInfo cameraInfo)

Gets all supported qualities on the device.

static boolean isQualitySupported(CameraInfo cameraInfo,