QualitySelector


class 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 SD, HD, FHD and UHD, but not all of them are supported on every device since each device has its own capabilities. isQualitySupported can be used to check whether a quality is supported on the device or not and getResolution 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 LOWEST or 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 with an open-ended fallback strategy such as a fallback strategy from lowerQualityOrHigherThan:
  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 functions

java-static QualitySelector
from(quality: Quality)

Gets an instance of QualitySelector with a desired quality.

java-static QualitySelector
from(quality: Quality, fallbackStrategy: FallbackStrategy)

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

java-static QualitySelector

Gets an instance of QualitySelector with ordered desired qualities.

java-static QualitySelector
fromOrderedList(
    qualities: (Mutable)List<Quality!>,
    fallbackStrategy: FallbackStrategy
)

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

java-static Size?
getResolution(cameraInfo: CameraInfo, quality: Quality)

Gets the corresponding resolution from the input quality.

java-static (Mutable)List<Quality!>

This function is deprecated.

use getSupportedQualities instead.

java-static Boolean
isQualitySupported(cameraInfo: CameraInfo, quality: Quality)

This function is deprecated.

use isQualitySupported instead.

String

Public functions

from

Added in 1.1.0
java-static fun from(quality: Quality): QualitySelector

Gets an instance of QualitySelector with a desired quality.

Parameters
quality: Quality

the quality. Possible values include LOWEST, HIGHEST, SD, HD, FHD, or UHD.

Returns
QualitySelector

the QualitySelector instance.

Throws
java.lang.NullPointerException

if quality is null.

java.lang.IllegalArgumentException

if quality is not one of the possible values.

from

Added in 1.1.0
java-static fun from(quality: Quality, fallbackStrategy: FallbackStrategy): QualitySelector

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 FallbackStrategy API such as lowerQualityThan.

Parameters
quality: Quality

the quality. Possible values include LOWEST, HIGHEST, SD, HD, FHD, or UHD.

fallbackStrategy: FallbackStrategy

the fallback strategy that will be applied when the device does not support quality.

Returns
QualitySelector

the QualitySelector instance.

Throws
java.lang.NullPointerException

if quality is null or fallbackStrategy is null.

java.lang.IllegalArgumentException

if quality is not one of the possible values.

fromOrderedList

Added in 1.1.0
java-static fun fromOrderedList(qualities: (Mutable)List<Quality!>): QualitySelector

Gets an instance of QualitySelector with ordered desired qualities.

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

Parameters
qualities: (Mutable)List<Quality!>

the quality list. Possible values include LOWEST, HIGHEST, SD, HD, FHD, or UHD.

Returns
QualitySelector

the QualitySelector instance.

Throws
java.lang.NullPointerException

if qualities is null.

java.lang.IllegalArgumentException

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
java-static fun fromOrderedList(
    qualities: (Mutable)List<Quality!>,
    fallbackStrategy: FallbackStrategy
): QualitySelector

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 FallbackStrategy API such as lowerQualityThan.

Parameters
qualities: (Mutable)List<Quality!>

the quality list. Possible values include LOWEST, HIGHEST, SD, HD, FHD, or UHD.

fallbackStrategy: FallbackStrategy

the fallback strategy that will be applied when the device does not support those qualities.

Throws
java.lang.NullPointerException

if qualities is null or fallbackStrategy is null.

java.lang.IllegalArgumentException

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
java-static fun getResolution(cameraInfo: CameraInfo, quality: Quality): Size?

Gets the corresponding resolution from the input quality.

Possible values for quality include LOWEST, HIGHEST, SD, HD, FHD and UHD.

Parameters
cameraInfo: CameraInfo

the cameraInfo for checking the quality.

quality: Quality

one of the quality constants.

Returns
Size?

the corresponding resolution from the input quality, or null if the quality is not supported on the device. isQualitySupported can be used to check if the input quality is supported.

Throws
java.lang.IllegalArgumentException

if quality is not one of the possible values.

getSupportedQualities

Added in 1.1.0
Deprecated in 1.3.0
java-static fun getSupportedQualities(cameraInfo: CameraInfo): (Mutable)List<Quality!>

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, isQualitySupported will return true and getResolution will return the corresponding resolution.

Note: Constants HIGHEST and LOWEST are not included in the returned list, but their corresponding qualities are included.

Parameters
cameraInfo: CameraInfo

the cameraInfo

isQualitySupported

Added in 1.1.0
Deprecated in 1.3.0
java-static fun isQualitySupported(cameraInfo: CameraInfo, quality: Quality): Boolean

Checks if the quality is supported.

Calling this method with one of the qualities contained in the returned list of getSupportedQualities will return true.

Possible values for quality include LOWEST, HIGHEST, SD, HD, FHD and UHD.

If this method is called with LOWEST or HIGHEST, it will return true except the case that none of the qualities can be supported.

Parameters
cameraInfo: CameraInfo

the cameraInfo for checking the quality.

quality: Quality

one of the quality constants.

Returns
Boolean

true if the quality is supported; false otherwise.

toString

fun toString(): String