public class VideoCaptureConstraints

  1. Object
  2. VideoCaptureConstraints

Encapsulates constraints that can be used for capturing video.

You should set the preferred constraints then if they are supported using #isSupported(), #isSizeSupported(), #isQualitySupported(), #isMaxLengthSupported(), or #isMaxFileSizeSupported(). If all of the constraints are supported, then, #isSupported() will return true, and the resolved constraints (#getWidth(), #getHeight(), #getQuality(), #getMaxLength(), #getMaxLength()) will match their preferred counterparts.

If #isSupported() is false, then at least one of the constraints is not supported by the system. You can check support for a specific constraint using #isSizeSupported(), #isMaxFileSizeSupported(), #isQualitySupported(), or #isMaxLengthSupported().

Example Using size and duration constraints:

`// Create capture constraint 320x240, with max length 20 seconds
VideoCaptureConstraints vcc = new VideoCaptureConstraints(320, 240, 20);
if (vcc.isSupported()) {
    // These constraints are fully supported by this platform
    // We can pass them directly to Capture.captureVideo() and the resulting
    // video will match the constraints exactly.
    // At this point, the following conditions are guaranteed to be true:
    // 1. vcc.getPreferredWidth() == vcc.getWidth() == 320
    // 2. vcc.getPreferredHeight() == vcc.getHeight() == 320
    // 3. vcc.getPreferredMaxLength() == vcc.getMaxLength() == 20` else {
    // At least one of the constraints is not supported.
    // You can find out the "granted" constraints using getWidth(), getHeight(),
    // and getMaxLength().
}
}

Example Using Quality:

`//
VideoCaptureConstraints vcc = new VideoCaptureConstraints(VideoCaptureConstraints.QUALITY_LOW);
if (vcc.isSupported()) {
    // This platform supports a 'low quality' setting.
    //  Low quality generally means a smaller file size.` else {
    // Low quality constraint is not supported.
}
}

Platform Support Status

Android #preferredQuality(int), #preferredMaxLength(int), and #preferredMaxFileSize(long) natively. It doesn’t fully support specific widths and heights, but if #preferredWidth(int), and #preferredHeight(int) are supplied, it will translate these into either #QUALITY_LOW, or #QUALITY_HIGH.

Javascript supports …. TODO Add support for javascript and others

Nested types

interface VideoCaptureConstraints.CompilerAn interface that will be implemented by the implementation.

Fields

public static final int QUALITY_LOW = 1
public static final int QUALITY_HIGH = 2

Constructors

public VideoCaptureConstraints()Creates a new video cosntraint with no constraints specified.
public VideoCaptureConstraints(VideoCaptureConstraints toCopy)Copy constructor.
public VideoCaptureConstraints(int quality)Creates a new constraint with the given quality constraint.
public VideoCaptureConstraints(int width, int height, int maxLength)Creates a new constraints with given preferred values.

Methods

public static void init(VideoCaptureConstraints.Compiler cmp)Deprecated Sets the native platform constraint compiler.
public String toString()Returns a string representation of the object.
public boolean equals(Object obj)Indicates whether some other object is “equal to” this one.
public int hashCode()Returns a hash code value for the object.
public long getMaxFileSize()Gets the maximum file size of the capture in bytes.
public VideoCaptureConstraints preferredMaxFileSize(long size)Sets the preferred max file size.
public long getPreferredMaxFileSize()Gets the preferred max file size.
public int getMaxLength()Returns the maximum length (in seconds) of this constraint.
public VideoCaptureConstraints preferredMaxLength(int maxLength)Set the preferred max length for the video capture in seconds.
public int getPreferredMaxLength()Gets the preferred max length video capture, in seconds.
public boolean isMaxLengthSupported()Checks to see if the preferred max length specified in this constraint is supported by the underlying platform.
public int getWidth()Gets the width constraint that is supported by the platform, and is nearest to the specified preferred width.
public int getPreferredWidth()Gets the preferred width constraint.
public int getPreferredHeight()Gets the preferred height constraint.
public boolean isSizeSupported()Checks if the specified preferred width and height constraints are supported by the platform.
public VideoCaptureConstraints preferredWidth(int width)Sets the preferred width constraint.
public int getHeight()Gets the platform-supported height constraint.
public VideoCaptureConstraints preferredHeight(int height)Sets the preferred height constraint.
public int getPreferredQuality()Gets the preferred quality of the recording.
public int getQuality()Gets the quality of the recording.
public VideoCaptureConstraints preferredQuality(int quality)Sets the preferred quality of the video recording.
public boolean isSupported()Checks if this constraint is fully supported by the platform.
public boolean isQualitySupported()Checks if the preferred quality setting is supported.
public boolean isMaxFileSizeSupported()Checks if the max file size constraint is supported.
public boolean isNullConstraint()Checks if this constraint is effectively a null constraint.

Inherited methods

Field details

QUALITY_LOW

public static final int QUALITY_LOW = 1

QUALITY_HIGH

public static final int QUALITY_HIGH = 2

Constructor details

VideoCaptureConstraints

public VideoCaptureConstraints()
Creates a new video cosntraint with no constraints specified.

VideoCaptureConstraints

public VideoCaptureConstraints(VideoCaptureConstraints toCopy)
Copy constructor.

VideoCaptureConstraints

public VideoCaptureConstraints(int quality)
Creates a new constraint with the given quality constraint.

Parameters

quality int
The quality of the constraint. Should be one of #QUALITY_LOW or #QUALITY_HIGH

VideoCaptureConstraints

public VideoCaptureConstraints(int width, int height, int maxLength)
Creates a new constraints with given preferred values.

Parameters

width int
The preferred width. Pass 0 for no constraint.
height int
The preferred height. Pass 0 for no constraint.
maxLength int
The preferred max length in seconds. Pass 0 for no consraint.

Method details

init

public static void init(VideoCaptureConstraints.Compiler cmp)
Deprecated. Called by the platform. For internal use only.
Sets the native platform constraint compiler. Should be called once during platform initialization.

toString

public String toString()
Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + ‘@’ + Integer.toHexString(hashCode())

equals

public boolean equals(Object obj)
Indicates whether some other object is “equal to” this one. The equals method implements an equivalence relation: It is reflexive: for any reference value x, x.equals(x) should return true. It is symmetric: for any reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true. It is transitive: for any reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true. It is consistent: for any reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the object is modified. For any non-null reference value x, x.equals(null) should return false. The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true).

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. The general contract of hashCode is: Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables. As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

getMaxFileSize

public long getMaxFileSize()
Gets the maximum file size of the capture in bytes.

Returns

The max file size.

preferredMaxFileSize

public VideoCaptureConstraints preferredMaxFileSize(long size)
Sets the preferred max file size.

Parameters

size long
The max file size in bytes.

Returns

Self for chaining

getPreferredMaxFileSize

public long getPreferredMaxFileSize()
Gets the preferred max file size.

Returns

The preferred max file size, in bytes.

getMaxLength

public int getMaxLength()

Returns the maximum length (in seconds) of this constraint.

This method always returns the resolved value that the platform supports. If the platform doesn’t support setting the max length of a video capture, then this will return 0. If it supports the value of #getPreferredMaxLength(), then this will return the same value. If it supports limiting the length of video capture, but it doesn’t support the preferred max length value, then this will return the closest that the platform can provide to the preferred value.

Note: This value will be equal to #getPreferredMaxLength() iff #isMaxLengthSupported() is true.

Returns

the maxLength The maximum length, in seconds, for the video capture. Zero for no limit.

preferredMaxLength

public VideoCaptureConstraints preferredMaxLength(int maxLength)

Set the preferred max length for the video capture in seconds.

If the platform supports this value, then #getMaxLength() will return this same value. If the platform does not support this value, then #getMaxLength() will return the closest value that the platform supports.

Parameters

maxLength int
the maxLength to set, in seconds. Set 0 for no limit.

Returns

Self for chaining

getPreferredMaxLength

public int getPreferredMaxLength()
Gets the preferred max length video capture, in seconds.

Returns

The preferred max length, in seconds.

isMaxLengthSupported

public boolean isMaxLengthSupported()
Checks to see if the preferred max length specified in this constraint is supported by the underlying platform.

Returns

True if and only if the preferred max length value is supported by the underlying platform.

getWidth

public int getWidth()
Gets the width constraint that is supported by the platform, and is nearest to the specified preferred width. If the platform supports the preferred width constraint, then #getPreferredWidth() will be the same as #getWidth(). If the platform doesn’t support any width constraints at all then this will return 0. If the platform supports some width constraints, but not the constraint specified, then this will return the most nearest value that the platform supports.

Returns

the Platform-supported width of this constraint.

getPreferredWidth

public int getPreferredWidth()
Gets the preferred width constraint.

Returns

The preferred width constraint.

getPreferredHeight

public int getPreferredHeight()
Gets the preferred height constraint.

Returns

The preferred height constraint.

isSizeSupported

public boolean isSizeSupported()
Checks if the specified preferred width and height constraints are supported by the platform.

Returns

True if the platform supports the width and height constraints specified directly.

preferredWidth

public VideoCaptureConstraints preferredWidth(int width)
Sets the preferred width constraint.

Parameters

width int
the width to set

getHeight

public int getHeight()
Gets the platform-supported height constraint. If the platform supports the preferred height constraint, then this will return the same value as #getPreferredHeight(). If the platform doesn’t support any height constraints, then this will return 0. If the platform supports height constraints, but not the specific preferred height value, then this will return the nearest value that is supported by the platform.

Returns

the platform-supported height constraint.

preferredHeight

public VideoCaptureConstraints preferredHeight(int height)
Sets the preferred height constraint.

Parameters

height int
the height to set

getPreferredQuality

public int getPreferredQuality()
Gets the preferred quality of the recording.

Returns

May be one of #QUALITY_LOW, #QUALITY_HIGH, or 0.

getQuality

public int getQuality()
Gets the quality of the recording.

Returns

May be one of #QUALITY_LOW, #QUALITY_HIGH, or 0.

preferredQuality

public VideoCaptureConstraints preferredQuality(int quality)
Sets the preferred quality of the video recording.

Parameters

quality int
May be one of #QUALITY_LOW, #QUALITY_HIGH, or 0.

Returns

Self for chaining

isSupported

public boolean isSupported()
Checks if this constraint is fully supported by the platform.

Returns

True if the constrains described in this object are fully supported by the platform.

isQualitySupported

public boolean isQualitySupported()
Checks if the preferred quality setting is supported.

Returns

True if the preferred quality is not set (i.e. 0), or is supported by the platform.

isMaxFileSizeSupported

public boolean isMaxFileSizeSupported()
Checks if the max file size constraint is supported.

Returns

true if the max file size constraint is supported, or the max file size constraint isn’t set.

isNullConstraint

public boolean isNullConstraint()
Checks if this constraint is effectively a null constraint. I.e. it doesn’t include any width, height, or max length constraints.

Returns

True if this constraints is effectively null.