public class MaterialCameraCapture extends gwt.material.design.client.base.MaterialWidget implements HasCameraCaptureHandlers
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.Featurecom.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled| Modifier and Type | Field and Description |
|---|---|
protected boolean |
pauseOnUnload |
| Constructor and Description |
|---|
MaterialCameraCapture() |
| Modifier and Type | Method and Description |
|---|---|
com.google.gwt.event.shared.HandlerRegistration |
addCameraCaptureHandler(CameraCaptureHandler handler)
Adds a CameraCaptureHandler.
|
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.
|
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.
|
protected String |
nativeCaptureToDataURL(com.google.gwt.dom.client.CanvasElement canvas,
com.google.gwt.dom.client.Element video,
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 |
restart()
Restarts the video stream from the camera.
|
void |
setPauseOnUnload(boolean pauseOnUnload)
Sets if the camera capture should pause when the widget is unloaded.
|
add, add, clearActiveClass, enableFeature, getBackgroundColor, getCenterOn, getCenterOnMixin, getCircleMixin, getColorsMixin, getDataAttribute, getDepth, getEnabledMixin, getFlexboxMixin, getFloat, getFloatMixin, getFocusableMixin, getFontSize, getFontSizeMixin, getFontWeight, getFontWeightMixin, getGridMixin, getHideOn, getHideOnMixin, getHoverableMixin, getId, getIdMixin, getInitialClasses, getOpacity, getScrollspy, getScrollspyMixin, getSeparatorMixin, getShadow, getShadowMixin, getShowOn, getShowOnMixin, getTabIndex, getTextAlign, getTextAlignMixin, getTextColor, getTooltip, getTooltipDelayMs, getTooltipMixin, getTooltipPosition, getTruncateMixin, getWaves, getWavesMixin, getWidth, getWidth, insert, insert, isCircle, isEnabled, isFeatureEnabled, isHoverable, isSeparator, setAccessKey, setBackgroundColor, setBottom, setCenterOn, setCircle, setDataAttribute, setDepth, 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, setMargin, setMarginBottom, setMarginLeft, setMarginRight, setMarginTop, setOffset, setOpacity, setOverflow, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRight, setPaddingTop, setRight, setScrollspy, setSeparator, setShadow, setShowOn, setTabIndex, setTextAlign, setTextColor, setTooltip, setTooltipDelayMs, setTooltipPosition, setTop, setTruncate, setVisibility, setWaves, stopTouchStartEvent, stopTouchStartEventadd, adjustIndex, checkIndexBoundsForAccess, checkIndexBoundsForInsertion, getChildren, getWidget, getWidgetCount, getWidgetIndex, getWidgetIndex, insert, iterator, remove, removeadd, adopt, clear, doAttachChildren, doDetachChildren, orphan, removeaddAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, removeFromParent, setLayoutData, sinkEvents, unsinkEventsaddStyleDependentName, 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, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorprotected boolean pauseOnUnload
public MaterialCameraCapture()
public String captureToDataURL()
captureToDataURL(String) using "image/png".public String captureToDataURL(String mimeType)
mimeType - The type of the output image, such as "image/png" or "image/jpeg".protected void onLoad()
onLoad in class gwt.material.design.client.base.MaterialWidgetprotected void onUnload()
onUnload in class com.google.gwt.user.client.ui.Widgetpublic void play()
Starts the video stream from the camera. This is called when the component is loaded.
Use CameraCaptureHandlers 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 CameraCaptureHandlers.
public void restart()
public void pause()
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 video, String mimeType)
public static boolean isSupported()
true if the browser supports this widget, false otherwiseprotected void onCameraCaptureLoad()
protected void onCameraCapturePause()
protected void onCameraCaptureError(String error)
public com.google.gwt.event.shared.HandlerRegistration addCameraCaptureHandler(CameraCaptureHandler handler)
HasCameraCaptureHandlersaddCameraCaptureHandler in interface HasCameraCaptureHandlersCopyright © 2016. All rights reserved.