Class MediaPlayer
- All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>
Video playback component with control buttons for back, play/pause and forward buttons. In the simulator those controls are implemented locally but on the device the native playback controls are used.
final Form hi = new Form("MediaPlayer", new BorderLayout());
hi.setToolbar(new Toolbar());
Style s = UIManager.getInstance().getComponentStyle("Title");
FontImage icon = FontImage.createMaterial(FontImage.MATERIAL_VIDEO_LIBRARY, s);
hi.getToolbar().addCommandToRightBar(new Command("", icon) {
@Override
public void actionPerformed(ActionEvent evt) {
Display.getInstance().openGallery((e) -> {
if(e != null && e.getSource() != null) {
String file = (String)e.getSource();
try {
Media video = MediaManager.createMedia(file, true);
hi.removeAll();
hi.add(BorderLayout.CENTER, new MediaPlayer(video));
hi.revalidate();
} catch(IOException err) {
Log.e(err);
}
}
}, Display.GALLERY_VIDEO);
}
});
hi.show();
-
Field Summary
Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected DimensionCalculates the preferred size based on component content.protected voidInvoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.Returns
Convenience JavaBean method, see other version of this methodReturns
getMedia()Returns the Media Object of this MediaPlayerReturns
Returns
String[]A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder codeClass[]Matches the property names method (see that method for further details).getPropertyValue(String name) Returns the current value of the property name, this method is used by the GUI builderUIID for the seekBar slidervoidHides the controls for this media player.protected voidAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component statebooleanSets playback to start automaticallybooleanOn platforms that include native video player controls (Android and iOS), this indicates whether these controls should be hidden for this media player.booleanisLoop()Sets playback to loopbooleanIncludes a maximize icon in the bar to show the native playerbooleanShows the buttons on top of the videobooleanShows video position bar as a slidervoidrun()voidsetAutoplay(boolean autoplay) Sets playback to start automaticallyvoidsetBackIcon(Image backIcon) Sets the back Button IconvoidsetDataSource(InputStream is, String mimeType, Runnable onCompletion) Sets the data source of this video playervoidsetDataSource(String uri) Convenience JavaBean method, see other version of this methodvoidsetDataSource(String uri, Runnable onCompletion) Sets the data source of this video playervoidsetFwdIcon(Image fwdIcon) Sets the forward Button IconvoidsetHideNativeVideoControls(boolean hideNativeControls) On platforms that include native video player controls (Android and iOS), this allows you to hide those controls.voidsetLoop(boolean loop) Sets playback to loopvoidsetMaxIcon(Image maxIcon) Sets the maximize Button IconvoidsetMaximize(boolean maximize) Includes a maximize icon in the bar to show the native playervoidsetOnTopMode(boolean onTopMode) Shows the buttons on top of the videovoidsetPauseIcon(Image pauseIcon) Sets the pause Button IconvoidsetPlayIcon(Image playIcon) Sets the play Button IconsetPropertyValue(String name, Object value) Sets a new value to the given property, returns an error message if failed and null if successful.voidsetSeekBar(boolean seekBar) Shows video position bar as a slidervoidsetSeekBarUIID(String seekBarUIID) UIID for the seekBar slidervoidShows the controls for this media player.booleanChecks to see if this player uses native video controls.Methods inherited from class Container
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndicesMethods inherited from class Component
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyTypeNames, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContainsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
MediaPlayer
public MediaPlayer()Empty constructor -
MediaPlayer
Empty constructor
-
-
Method Details
-
isHideNativeVideoControls
public boolean isHideNativeVideoControls()On platforms that include native video player controls (Android and iOS), this indicates whether these controls should be hidden for this media player.
Returns
true if native video player controls should be hidden.
See also
-
Display#isNativeVideoPlayerControlsIncluded()
-
#setHideNativeVideoControls(boolean)
-
#usesNativeVideoControls()
-
-
setHideNativeVideoControls
public void setHideNativeVideoControls(boolean hideNativeControls) On platforms that include native video player controls (Android and iOS), this allows you to hide those controls.
Parameters
hideNativeControls: Set true to hide the native video controls for this player.
See also
-
Display#isNativeVideoPlayerControlsIncluded()
-
#setHideNativeVideoControls(boolean)
-
#usesNativeVideoControls()
-
usesNativeVideoControls
public boolean usesNativeVideoControls()Checks to see if this player uses native video controls. For this to be true, the platform must support native video controls (iOS and Android) (See
Display#isNativeVideoPlayerControlsIncluded()to find out if current platform supports this; AND#isHideNativeVideoControls()must be false.Note: on IOS, the controls won't display until the video's
Media#prepare()is called. This will happen automatically if#isAutoplay()is true, or ifMedia#play()is called.Returns
True if this player uses native video controls.
See also
-
#isHideNativeVideoControls()
-
#setHideNativeVideoControls(boolean)
-
Display#isNativeVideoPlayerControlsIncluded()
-
-
showControls
public void showControls()Shows the controls for this media player. If the player is set to use native controls, then this will show the native controls. Otherwise it shows the lightweight controls.
Note: on IOS, the controls won't display until the video's
Media#prepare()is called. This will happen automatically if#isAutoplay()is true, or ifMedia#play()is called. -
hideControls
public void hideControls()Hides the controls for this media player. If the player is set to use native controls, then this will hide the native controls. Otherwise it hides the lightweight controls. -
getMedia
Returns the Media Object of this MediaPlayer -
initComponent
protected void initComponent()Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state- Overrides:
initComponentin classComponent
-
deinitialize
protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.- Overrides:
deinitializein classComponent
-
calcPreferredSize
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.
Returns
the calculated preferred size based on component content
- Overrides:
calcPreferredSizein classContainer
-
setMaxIcon
Sets the maximize Button Icon
Parameters
maxIcon
-
setDataSource
Sets the data source of this video player
Parameters
uri: @param uri the uri of the media can start with file://, http:// (can also use rtsp:// although may not be supported on all target platforms)
Throws
IOException: if creation of media from the given URI has failed
- Throws:
IOException
-
getDataSource
Convenience JavaBean method, see other version of this method
Returns
the data source uri
-
setDataSource
Convenience JavaBean method, see other version of this method
Parameters
uri: the URL for the media
-
setDataSource
public void setDataSource(InputStream is, String mimeType, Runnable onCompletion) throws IOException Sets the data source of this video player
Parameters
-
is: the stream containing the media data -
mimeType: the type of the data in the stream
Throws
java.io.IOException: if the creation of the Media has failed
- Throws:
IOException
-
-
run
public void run() -
getPropertyNames
A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code
Returns
the property names allowing mutation
- Overrides:
getPropertyNamesin classComponent
-
getPropertyTypes
Matches the property names method (see that method for further details).
Returns
the types of the properties
- Overrides:
getPropertyTypesin classComponent
-
getPropertyValue
Returns the current value of the property name, this method is used by the GUI builder
Parameters
name: the name of the property
Returns
the value of said property
- Overrides:
getPropertyValuein classComponent
-
setPropertyValue
Sets a new value to the given property, returns an error message if failed and null if successful. Notice that some builtin properties such as "$designMode" might be sent to components to indicate application state.
Parameters
-
name: the name of the property -
value: new value for the property
Returns
error message or null
- Overrides:
setPropertyValuein classComponent
-
-
getPlayIcon
Returns
the playIcon
-
setPlayIcon
Sets the play Button Icon
Parameters
playIcon
-
getPauseIcon
Returns
the pauseIcon
-
setPauseIcon
Sets the pause Button Icon
Parameters
pauseIcon
-
getBackIcon
Returns
the backIcon
-
setBackIcon
Sets the back Button Icon
Parameters
backIcon
-
getFwdIcon
Returns
the fwdIcon
-
setFwdIcon
Sets the forward Button Icon
Parameters
fwdIcon
-
isAutoplay
public boolean isAutoplay()Sets playback to start automatically
Returns
the autoplay
-
setAutoplay
public void setAutoplay(boolean autoplay) Sets playback to start automatically
Parameters
autoplay: the autoplay to set
-
isLoop
public boolean isLoop()Sets playback to loop
Returns
the loop
-
setLoop
public void setLoop(boolean loop) Sets playback to loop
Parameters
loop: the loop to set
-
isOnTopMode
public boolean isOnTopMode()Shows the buttons on top of the video
Returns
the onTopMode
-
setOnTopMode
public void setOnTopMode(boolean onTopMode) Shows the buttons on top of the video
Parameters
onTopMode: the onTopMode to set
-
isSeekBar
public boolean isSeekBar()Shows video position bar as a slider
Returns
the seekBar
-
setSeekBar
public void setSeekBar(boolean seekBar) Shows video position bar as a slider
Parameters
seekBar: the seekBar to set
-
getSeekBarUIID
UIID for the seekBar slider
Returns
the seekBarUIID
-
setSeekBarUIID
UIID for the seekBar slider
Parameters
seekBarUIID: the seekBarUIID to set
-
isMaximize
public boolean isMaximize()Includes a maximize icon in the bar to show the native player
Returns
the maximize
-
setMaximize
public void setMaximize(boolean maximize) Includes a maximize icon in the bar to show the native player
Parameters
maximize: the maximize to set
-