# Class VideoCaptureConstraints

java.lang.Object
com.codename1.capture.VideoCaptureConstraints

public class VideoCaptureConstraints extends Object

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 Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `VideoCaptureConstraints.Compiler`
  An interface that will be implemented by the implementation.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `QUALITY_HIGH`
  `static final int`
  `QUALITY_LOW`

- ## Constructor Summary

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

- ## Method Summary

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

  ### Methods inherited from class Object

  `clone, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### QUALITY_LOW

    public static final int QUALITY_LOW
    See Also:
      - Constant Field Values

  - ### QUALITY_HIGH

    public static final int QUALITY_HIGH
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### VideoCaptureConstraints

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

  - ### VideoCaptureConstraints

    public VideoCaptureConstraints(VideoCaptureConstraints toCopy)

    Copy constructor.

    ###### Parameters

    - `toCopy`

  - ### VideoCaptureConstraints

    public VideoCaptureConstraints(int quality)

    Creates a new constraint with the given quality constraint.

    ###### Parameters

    - `quality`: 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`: The preferred width. Pass 0 for no constraint.

    - `height`: The preferred height. Pass 0 for no constraint.

    - `maxLength`: The preferred max length in seconds. Pass 0 for no consraint.

- ## Method Details

  - ### init

    public static void init(VideoCaptureConstraints.Compiler cmp)

    Sets the native platform constraint compiler. Should be called once during platform initialization.

    ###### Parameters

    - `cmp`

    ###### Deprecated

    Called by the platform. For internal use only.

  - ### toString

    public String toString()
    Description copied from class: `Object`
    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())
    Overrides:
      `toString` in class `Object`

  - ### equals

    public boolean equals(Object obj)
    Description copied from class: `Object`
    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).
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Description copied from class: `Object`
    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.)
    Overrides:
      `hashCode` in class `Object`

  - ### getMaxFileSize

    public long getMaxFileSize()

    Gets the maximum file size of the capture in bytes.

    ###### Returns

    The max file size.

    ###### See also

    - #preferredMaxFileSize(long)

  - ### preferredMaxFileSize

    public VideoCaptureConstraints preferredMaxFileSize(long size)

    Sets the preferred max file size.

    ###### Parameters

    - `size`: The max file size in bytes.

    ###### Returns

    Self for chaining

    ###### See also

    - #getMaxFileSize()

    - #isMaxFileSizeSupported()

  - ### getPreferredMaxFileSize

    public long getPreferredMaxFileSize()

    Gets the preferred max file size.

    ###### Returns

    The preferred max file size, in bytes.

    ###### See also

    - #preferredMaxFileSize(long)

    - #getMaxFileSize()

    - #isMaxFileSizeSupported()

  - ### 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.

    ###### See also

    - #isMaxLengthSupported()

    - #preferredMaxLength(int)

    - #getPreferredMaxLength()

  - ### 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`: the maxLength to set, in seconds. Set 0 for no limit.

    ###### Returns

    Self for chaining

    ###### See also

    - #getPreferredMaxLength()

    - #getMaxLength()

    - #isMaxLengthSupported()

  - ### getPreferredMaxLength

    public int getPreferredMaxLength()

    Gets the preferred max length video capture, in seconds.

    ###### Returns

    The preferred max length, in seconds.

    ###### See also

    - #preferredMaxLength(int)

    - #getMaxLength()

    - #isMaxLengthSupported()

  - ### 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.

    ###### See also

    - #getMaxLength()

    - #preferredMaxLength(int)

    - #getPreferredMaxLength()

  - ### 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.

    ###### See also

    - #getPreferredWidth()

    - #isSizeSupported()

    - #preferredWidth(int)

  - ### getPreferredWidth

    public int getPreferredWidth()

    Gets the preferred width constraint.

    ###### Returns

    The preferred width constraint.

    ###### See also

    - #getWidth()

    - #preferredWidth(int)

    - #isSizeSupported()

  - ### getPreferredHeight

    public int getPreferredHeight()

    Gets the preferred height constraint.

    ###### Returns

    The preferred height constraint.

    ###### See also

    - #getHeight()

    - #preferredHeight(int)

    - #isSizeSupported() `

  - ### 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.

    ###### See also

    - #getWidth()

    - #getHeight()

    - #getPreferredWidth()

    - #getPreferredHeight()

    - #preferredWidth(int)

    - #preferredHeight(int)

    - #isSupported()

  - ### preferredWidth

    public VideoCaptureConstraints preferredWidth(int width)

    Sets the preferred width constraint.

    ###### Parameters

    - `width`: the width to set

    ###### See also

    - #getWidth()

    - #getPreferredWidth()

    - #isSizeSupported()

  - ### 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.

    ###### See also

    - #getPreferredHeight()

    - #preferredHeight(int)

    - #isSizeSupported()

  - ### preferredHeight

    public VideoCaptureConstraints preferredHeight(int height)

    Sets the preferred height constraint.

    ###### Parameters

    - `height`: the height to set

    ###### See also

    - #getPreferredHeight()

    - #getHeight()

    - #isSizeSupported()

  - ### getPreferredQuality

    public int getPreferredQuality()

    Gets the preferred quality of the recording.

    ###### Returns

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

    ###### See also

    - #preferredQuality(int)

    - #isQualitySupported()

    - #getQuality()

  - ### getQuality

    public int getQuality()

    Gets the quality of the recording.

    ###### Returns

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

    ###### See also

    - #getPreferredQuality()

    - #preferredQuality(int)

    - #isQualitySupported()

  - ### preferredQuality

    public VideoCaptureConstraints preferredQuality(int quality)

    Sets the preferred quality of the video recording.

    ###### Parameters

    - `quality`: May be one of `#QUALITY_LOW`, `#QUALITY_HIGH`, or 0.

    ###### Returns

    Self for chaining

    ###### See also

    - #getQuality()

    - #getPreferredQuality()

    - #isQualitySupported()

  - ### 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.

    ###### See also

    - #isSizeSupported()

    - #isMaxLengthSupported()

  - ### 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.

    ###### See also

    - #getPreferredQuality()

    - #getQuality()

    - #preferredQuality(int)

  - ### 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.

    ###### See also

    - #preferredMaxFileSize(long)

    - #getMaxFileSize()

    - #getPreferredMaxFileSize()

  - ### 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.