public class MaterialCameraCapture extends gwt.material.design.client.base.MaterialWidget implements gwt.material.design.client.base.JsLoader, HasCameraCaptureHandlers, HasCameraActions
MaterialCameraCapture is a widget that captures the video stream from the camera, using the
HTML5 MediaDevices.getUserMedia()
(Streams API). This widget can capture images from the video, to allow
the upload to the server of photos from the camera.
xmlns:ma='urn:import:gwt.material.design.addins.client'
<ma:camera.MaterialCameraCapture ui:field="camera" />
if (MaterialCameraCapture.isSupported()){ MaterialCameraCapture camera = new MaterialCameraCapture(); camera.addCameraCaptureHandler(new CameraCaptureHandler() { @Override public void onCameraCaptureChange(CameraCaptureEvent event) { if (event.getCaptureStatus() == CaptureStatus.ERRORED){ Window.alert("Error on starting the camera capture: " + event.getErrorMessage()); ((MaterialCameraCapture)event.getSource()).removeFromParent(); } } }); add(camera); //adds to the layout } else { Window.alert("Sorry, your browser doesn't support the camera capture."); }
To limit the width of the camera capture widget on mobile devices, you can use max-width: 100%
on the widget.
The browser will take care of the aspect ratio of the video.
This widget only works on pages served by a secure protocol (HTTPS). For the browser compatibility, access http://caniuse.com/#feat=stream
gwt.material.design.client.base.MaterialWidget.Feature
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled
Modifier and Type | Field and Description |
---|---|
protected CameraFacingMode |
facingMode |
protected int |
height |
protected boolean |
pauseOnUnload |
protected int |
width |
Constructor and Description |
---|
MaterialCameraCapture() |
Modifier and Type | Method and Description |
---|---|
com.google.gwt.event.shared.HandlerRegistration |
addCameraCaptureHandler(CameraCaptureHandler handler)
Adds a CameraCaptureHandler.
|
void |
addOverlay(gwt.material.design.client.base.MaterialWidget overlay) |
String |
captureToDataURL()
Captures the current frame of the video to an image data URL.
|
String |
captureToDataURL(String mimeType)
Captures the current frame of the video to an image data URL.
|
void |
clearOverlays() |
gwt.material.design.client.base.MaterialWidget |
getVideo() |
boolean |
isPauseOnUnload()
Returns if the camera capture should pause when the widget is unloaded.
|
static boolean |
isSupported()
Tests if the browser supports the Streams API.
|
void |
load() |
protected String |
nativeCaptureToDataURL(com.google.gwt.dom.client.CanvasElement canvas,
com.google.gwt.dom.client.Element element,
String mimeType)
Native call to capture the frame of the video stream.
|
protected void |
nativePlay(com.google.gwt.dom.client.Element video)
Native call to the streams API
|
protected void |
onCameraCaptureError(String error)
Called by the component when the stream when an error occurs.
|
protected void |
onCameraCaptureLoad()
Called by the component when the stream has started.
|
protected void |
onCameraCapturePause()
Called by the component when the stream has paused.
|
protected void |
onLoad() |
protected void |
onUnload() |
void |
pause()
Pauses the video stream from the camera.
|
void |
play()
Starts the video stream from the camera.
|
void |
reload() |
void |
removeOverlay(gwt.material.design.client.base.MaterialWidget overlay) |
void |
setFacingMode(CameraFacingMode facingMode)
Set the facing mode of the camera (Best usecase for Mobile Devices)
|
void |
setPauseOnUnload(boolean pauseOnUnload)
Sets if the camera capture should pause when the widget is unloaded.
|
void |
setResolution(int width,
int height)
Set the resolution of the camera
|
void |
setVideo(gwt.material.design.client.base.MaterialWidget video) |
void |
stop()
Stops all the Tracks that is currently streaming
|
void |
unload() |
$this, add, add, addAttachHandler, addBlurHandler, addClickHandler, addDoubleClickHandler, addDragEndHandler, addDragEnterHandler, addDragLeaveHandler, addDragMoveHandler, addDragOverHandler, addDragStartHandler, addDropActivateHandler, addDropDeactivateHandler, addDropHandler, addFocusHandler, addGestureChangeHandler, addGestureEndHandler, addGestureStartHandler, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addMouseDownHandler, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler, addOrientationChangeHandler, addTouchCancelHandler, addTouchEndHandler, addTouchMoveHandler, addTouchStartHandler, body, clearActiveClass, enableFeature, getBackfaceVisibility, getBackgroundColor, getBorder, getBorderBottom, getBorderLeft, getBorderMixin, getBorderRadius, getBorderRight, getBorderTop, getCenterOn, getCenterOnMixin, getChildren, getChildrenList, getCircleMixin, getColorsMixin, getDataAttribute, getDepth, getDimensionMixin, getEnabledMixin, getFlexboxMixin, getFloat, getFloatMixin, getFocusableMixin, getFontSize, getFontSizeMixin, getFontWeight, getFontWeightMixin, getGridMixin, getHandlerRegistry, getHideOn, getHideOnMixin, getHoverableMixin, getId, getIdMixin, getInitialClasses, getLayoutPosition, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpacity, getOrientation, getOrientationMixin, getPerspective, getPerspectiveOrigin, getScrollspy, getScrollspyMixin, getSeparatorMixin, getShadow, getShadowMixin, getShowOn, getShowOnMixin, getTabIndex, getTextAlign, getTextAlignMixin, getTextColor, getTooltip, getTooltipDelayMs, getTooltipHTML, getTooltipMixin, getTooltipPosition, getTransform, getTransformMixin, getTransformOrigin, getTransformStyle, getTruncateMixin, getVerticalAlign, getVerticalAlignMixin, getWaves, getWavesMixin, getWidth, insert, insert, isCircle, isDetectOrientation, isEnabled, isFeatureEnabled, isHoverable, isSeparator, isTruncate, registerHandler, removeHandler, setAccessKey, setBackfaceVisibility, setBackgroundColor, setBorder, setBorderBottom, setBorderLeft, setBorderRadius, setBorderRight, setBorderTop, setBottom, setCenterOn, setCircle, setClass, setDataAttribute, setDepth, setDetectOrientation, setDisplay, setEnabled, setFlex, setFlexAlignContent, setFlexAlignItems, setFlexAlignSelf, setFlexBasis, setFlexDirection, setFlexGrow, setFlexJustifyContent, setFlexOrder, setFlexShrink, setFlexWrap, setFloat, setFocus, setFontSize, setFontSize, setFontWeight, setGrid, setGwtDisplay, setHideOn, setHoverable, setId, setInitialClasses, setLayoutPosition, setLeft, setLineHeight, setMargin, setMarginBottom, setMarginLeft, setMarginRight, setMarginTop, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setOffset, setOpacity, setOrientation, setOverflow, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRight, setPaddingTop, setPerspective, setPerspectiveOrigin, setRight, setScrollspy, setSeparator, setShadow, setShowOn, setStyle, setTabIndex, setTextAlign, setTextColor, setTooltip, setTooltipDelayMs, setTooltipHTML, setTooltipPosition, setTop, setTransform, setTransformOrigin, setTransformStyle, setTransition, setTruncate, setVerticalAlign, setVisibility, setWaves, stopTouchStartEvent, validate, window
add, adjustIndex, checkIndexBoundsForAccess, checkIndexBoundsForInsertion, getWidget, getWidgetCount, getWidgetIndex, getWidgetIndex, insert, iterator, remove, remove
add, adopt, clear, doAttachChildren, doDetachChildren, orphan, remove
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
protected int width
protected int height
protected boolean pauseOnUnload
protected CameraFacingMode facingMode
public MaterialCameraCapture()
protected void onLoad()
onLoad
in class gwt.material.design.client.base.MaterialWidget
public void load()
load
in interface gwt.material.design.client.base.JsLoader
protected void onUnload()
onUnload
in class gwt.material.design.client.base.MaterialWidget
public void unload()
unload
in interface gwt.material.design.client.base.JsLoader
public void reload()
reload
in interface gwt.material.design.client.base.HasReload
public void play()
HasCameraActions
Starts the video stream from the camera. This is called when the component is loaded.
Use CameraCaptureHandler
s to be notified when the stream actually starts or if
an error occurs.
At this point the user is requested by the browser to allow the application to use the camera.
If the user doesn't allow it, an error is notified to the CameraCaptureHandler
s.
play
in interface HasCameraActions
public void pause()
HasCameraActions
pause
in interface HasCameraActions
public void stop()
HasCameraActions
stop
in interface HasCameraActions
public String captureToDataURL()
HasCameraActions
captureToDataURL(String)
using "image/png".captureToDataURL
in interface HasCameraActions
public String captureToDataURL(String mimeType)
HasCameraActions
captureToDataURL
in interface HasCameraActions
mimeType
- The type of the output image, such as "image/png" or "image/jpeg".public void setPauseOnUnload(boolean pauseOnUnload)
true
.public boolean isPauseOnUnload()
true
.protected void nativePlay(com.google.gwt.dom.client.Element video)
protected String nativeCaptureToDataURL(com.google.gwt.dom.client.CanvasElement canvas, com.google.gwt.dom.client.Element element, String mimeType)
public static boolean isSupported()
true
if the browser supports this widget, false
otherwisepublic void addOverlay(gwt.material.design.client.base.MaterialWidget overlay)
public void removeOverlay(gwt.material.design.client.base.MaterialWidget overlay)
public void clearOverlays()
public gwt.material.design.client.base.MaterialWidget getVideo()
public void setVideo(gwt.material.design.client.base.MaterialWidget video)
public void setResolution(int width, int height)
public void setFacingMode(CameraFacingMode facingMode)
protected void onCameraCaptureLoad()
protected void onCameraCapturePause()
protected void onCameraCaptureError(String error)
public com.google.gwt.event.shared.HandlerRegistration addCameraCaptureHandler(CameraCaptureHandler handler)
HasCameraCaptureHandlers
addCameraCaptureHandler
in interface HasCameraCaptureHandlers
Copyright © 2018. All rights reserved.