Class Camera

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Component, Scope, ComponentCtrl

    public class Camera
    extends XulElement
    A camera, use to record video and take snapshot, have a preview screen.

    Only works for browsers supporting HTML5 video tag

    Since:
    8.6.0
    Author:
    charlesqiu
    See Also:
    Serialized Form
    • Constructor Detail

      • Camera

        public Camera()
    • Method Detail

      • start

        public void start()
        Start recording.
      • start

        public void start​(double delay)
        Start recording. When camera is off (never call $requestCamera() before), after calling this method, it will request camera permission from user at first, the delay parameter indicates the duration between user permission obtaining and record starting in seconds.
        Parameters:
        delay - the duration between user permission obtaining and record starting in seconds, only meaningful when camera is off
      • stop

        public void stop()
        Stop recording.
      • pause

        public void pause()
        Pause recording.
      • resume

        public void resume()
        Resume recording.
      • snapshot

        public void snapshot()
        Take a snapshot.
      • snapshot

        public void snapshot​(double delay)
        Take a snapshot. When camera is off (never call $requestCamera() before), after calling this method, it will request camera permission from user at first, the delay parameter indicates the duration between user permission obtaining and taking snapshot in seconds.
        Parameters:
        delay - the duration between user permission obtaining and taking snapshot in seconds, only meaningful when camera is off
      • requestCamera

        public void requestCamera()
        Ask user for permissions to get media stream from camera and microphone.
      • stopStreaming

        public void stopStreaming()
        Stop getting media stream from user's camera and microphone.
      • isStopped

        public boolean isStopped()
        Return whether camera is stopped.
        Returns:
        true if the camera is stopped.
      • isPaused

        public boolean isPaused()
        Return whether camera is paused.
        Returns:
        true if the camera is paused.
      • isRecording

        public boolean isRecording()
        Return whether camera is recording.
        Returns:
        true if the camera is recording.
      • setRecording

        public void setRecording​(boolean recording)
        setRecording(true) means start or resume recording. setRecording(false) means stop recording. If you want to pause recording, please invoke pause().

        Parameters:
        recording - whether to start recording.
      • isAudio

        public boolean isAudio()
        Return whether to record sound while recording video.

        Default: true

        Returns:
        true if record sound function is on.
      • setAudio

        public void setAudio​(boolean audio)
        Set whether to record sound while recording video.
        Parameters:
        audio - whether to record sound.
      • setMaxsize

        public void setMaxsize​(int maxsize)
        Set the max size of upload video and snapshot, unit is "KB". Notice: Both video and snapshot files must smaller than max size, or nothing will upload.
        Parameters:
        maxsize - negative value is unlimited, 0 will use Configuration.getMaxUploadSize()
      • getLengthLimit

        public int getLengthLimit()
        Get the maximum record length limit, unit is "seconds". If recording seconds exceed length limit, recording will stop immediately.

        Default: 60

        Returns:
        maximum record length limit setting.
      • setLengthLimit

        public void setLengthLimit​(int lengthLimit)
        Set the maximum record length limit, unit is "seconds". If recording seconds exceed length limit, recording will stop immediately.
        Parameters:
        lengthLimit - setting maximum record length limit.
      • isPreviewRecord

        public boolean isPreviewRecord()
        Return whether the preview screen is on. If you want to take a snapshot, must turn on preview screen, or nothing will happen.

        Default: true

        Returns:
        true if preview screen is on.
      • setPreviewRecord

        public void setPreviewRecord​(boolean previewRecord)
        Set whether the preview screen is on. If you want to take a snapshot, must turn on preview screen, or nothing will happen.
        Parameters:
        previewRecord - whether to turn on preview screen.
      • getSnapshotFormat

        public java.lang.String getSnapshotFormat()
        Get the snapshot image format, e.g., image/png, image/jpeg. If the requested type is invalid or unspecified, it will use image/png.

        Default: null.

        Returns:
        snapshot format
      • setSnapshotFormat

        public void setSnapshotFormat​(java.lang.String snapshotFormat)
        Set the snapshot image format, e.g., image/png, image/jpeg. If the requested type is invalid or unspecified, it will use image/png.
        Parameters:
        snapshotFormat - snapshot format
      • getRecordFormat

        public java.lang.String getRecordFormat()
        Get the record video format, e.g., video/webm, video/mp4, video/ogg. If the requested type is invalid or unspecified, it will use video/webm.

        Default: null.

        Returns:
        recordFormat format
      • setRecordFormat

        public void setRecordFormat​(java.lang.String recordFormat)
        Set the record video format, e.g., video/webm, video/mp4, video/ogg. If the requested type is invalid or unspecified, it will use video/webm.
        Parameters:
        recordFormat - recordFormat format
      • getConstraints

        public java.util.Map getConstraints()
        Returns the constraints. About allowed constraints setting, see https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints Default: null.
        Returns:
        the constraints
      • setConstraints

        public void setConstraints​(java.util.Map constraints)
        Sets the constraints, if not specify constraints, it will use {audio: isAudio(), video: true}. About allowed constraints setting, see https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints
        Parameters:
        constraints - the constraints
      • getConstraintsString

        public java.lang.String getConstraintsString()
        Returns the constraints in JSON String format. About allowed constraints setting, see https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints

        Default: null.

        Returns:
        the constraints in JSON String format
      • setConstraintsString

        public void setConstraintsString​(java.lang.String constraints)
        Sets the constraints in JSON String format, if not specify constraints, it will use {audio: isAudio(), video: true}. About allowed constraints setting, see https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints
        Parameters:
        constraints - the constraints in JSON String format