# Class VideoCaptureConstraints

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

public class VideoCaptureConstraints extends java.lang.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(java.lang.Object obj)`
  `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()`
  `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()`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, 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()
    Overrides:
      `toString` in class `java.lang.Object`

  - ### equals

    public boolean equals(java.lang.Object obj)
    Overrides:
      `equals` in class `java.lang.Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `java.lang.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.