public class MediaPlayer
ImplementsAnimation, Editable, Iterable<Component>, StyleListener
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();
Constructors
public MediaPlayer() | Empty constructor |
public MediaPlayer(Media video) | Empty constructor |
Methods
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. |
public void setHideNativeVideoControls(boolean hideNativeControls) | On platforms that include native video player controls (Android and iOS), this allows you to hide those controls. |
public boolean usesNativeVideoControls() | Checks to see if this player uses native video controls. |
public void showControls() | Shows the controls for this media player. |
public void hideControls() | Hides the controls for this media player. |
public Media getMedia() | Returns the Media Object of this MediaPlayer |
protected void initComponent() | Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state |
protected void deinitialize() | Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. |
protected Dimension calcPreferredSize() | Calculates the preferred size based on component content. |
public void setMaxIcon(Image maxIcon) | Sets the maximize Button Icon |
public void setDataSource(String uri, Runnable onCompletion)
throws IOException | Sets the data source of this video player |
public String getDataSource() | Convenience JavaBean method, see other version of this method |
public void setDataSource(String uri) | Convenience JavaBean method, see other version of this method |
public void setDataSource(InputStream is, String mimeType, Runnable onCompletion)
throws IOException | Sets the data source of this video player |
public void run() | |
public String[] 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 |
public Class[] getPropertyTypes() | Matches the property names method (see that method for further details). |
public Object getPropertyValue(String name) | Returns the current value of the property name, this method is used by the GUI builder |
public String setPropertyValue(String name, Object value) | Sets a new value to the given property, returns an error message if failed and null if successful. |
public Image getPlayIcon() | |
public void setPlayIcon(Image playIcon) | Sets the play Button Icon |
public Image getPauseIcon() | |
public void setPauseIcon(Image pauseIcon) | Sets the pause Button Icon |
public Image getBackIcon() | |
public void setBackIcon(Image backIcon) | Sets the back Button Icon |
public Image getFwdIcon() | |
public void setFwdIcon(Image fwdIcon) | Sets the forward Button Icon |
public boolean isAutoplay() | Sets playback to start automatically |
public void setAutoplay(boolean autoplay) | Sets playback to start automatically |
public boolean isLoop() | Sets playback to loop |
public void setLoop(boolean loop) | Sets playback to loop |
public boolean isOnTopMode() | Shows the buttons on top of the video |
public void setOnTopMode(boolean onTopMode) | Shows the buttons on top of the video |
public boolean isSeekBar() | Shows video position bar as a slider |
public void setSeekBar(boolean seekBar) | Shows video position bar as a slider |
public String getSeekBarUIID() | UIID for the seekBar slider |
public void setSeekBarUIID(String seekBarUIID) | UIID for the seekBar slider |
public boolean isMaximize() | Includes a maximize icon in the bar to show the native player |
public void setMaximize(boolean maximize) | Includes a maximize icon in the bar to show the native player |
Inherited fields
From Component
DEFAULT_CURSOR, CROSSHAIR_CURSOR, TEXT_CURSOR, WAIT_CURSOR, SW_RESIZE_CURSOR, SE_RESIZE_CURSOR, NW_RESIZE_CURSOR, NE_RESIZE_CURSOR, N_RESIZE_CURSOR, S_RESIZE_CURSOR, W_RESIZE_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_Y, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_IMMEDIATELY_DRAG_XY, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET, BRB_OTHER, CENTER, TOP, LEFT, BOTTOM, RIGHT, BASELINE
Inherited methods
From Container
encloseIn, encloseIn, initLaf, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyPressed, keyReleased, getLayout, setLayout, invalidate, setShouldLayout, setShouldCalcPreferredSize, getLayoutWidth, getLayoutHeight, applyRTL, constrainWidthWhenScrollable, constrainHeightWhenScrollable, addComponent, addComponent, addComponent, addComponent, replaceAndWait, replaceAndWait, replace, replaceAndWait, replace, createReplaceTransition, isEnabled, setEnabled, removeComponent, cancelRepaints, flushReplace, removeAll, revalidateWithAnimationSafety, revalidate, revalidateLater, forceRevalidate, clearClientProperties, paint, paintGlass, layoutContainer, isSafeArea, setSafeArea, isSafeAreaRoot, getSafeAreaRoot, setSafeAreaRoot, getComponentCount, getComponentAt, getComponentIndex, contains, scrollComponentToVisible, getClosestComponentTo, getResponderAt, getComponentAt, findDropTargetAt, pointerPressed, paramString, refreshTheme, isScrollableX, setScrollableX, isScrollableY, setScrollableY, getSideGap, getBottomGap, setScrollable, setCellRenderer, getScrollIncrement, setScrollIncrement, findFirstFocusable, dragInitiated, fireClicked, isSelectableInteraction, getGridPosY, paintComponentBackground, getGridPosX, animateHierarchyAndWait, createAnimateHierarchy, animateHierarchy, animateHierarchyFadeAndWait, createAnimateHierarchyFade, animateHierarchyFade, animateLayoutFadeAndWait, createAnimateLayoutFadeAndWait, animateLayoutFade, createAnimateLayoutFade, animateLayoutAndWait, animateLayout, updateTabIndices, createAnimateLayout, drop, createAnimateMotion, morph, morphAndWait, animateUnlayout, animateUnlayoutAndWait, createAnimateUnlayout, getChildrenAsList, iterator, iterator
From Component
setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, animate, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyTypeNames, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip
Constructor details
MediaPlayer
public MediaPlayer()MediaPlayer
public MediaPlayer(Media video)Method details
isHideNativeVideoControls
public boolean isHideNativeVideoControls()Returns
setHideNativeVideoControls
public void setHideNativeVideoControls(boolean hideNativeControls)Parameters
hideNativeControlsboolean- Set true to hide the native video controls for this player.
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 if Media#play()
is called.
Returns
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 if Media#play()
is called.
hideControls
public void hideControls()getMedia
public Media getMedia()initComponent
protected void initComponent()deinitialize
protected void deinitialize()calcPreferredSize
protected Dimension calcPreferredSize()Returns
setMaxIcon
public void setMaxIcon(Image maxIcon)setDataSource
public void setDataSource(String uri, Runnable onCompletion)
throws IOExceptionParameters
uriString- the uri of the media can start with file://, http:// (can also use rtsp:// although may not be supported on all target platforms)
onCompletionRunnable- Not documented.
Throws
IOException- if creation of media from the given URI has failed
getDataSource
public String getDataSource()Returns
setDataSource
public void setDataSource(String uri)Parameters
uriString- the URL for the media
setDataSource
public void setDataSource(InputStream is, String mimeType, Runnable onCompletion)
throws IOExceptionParameters
isInputStream- the stream containing the media data
mimeTypeString- the type of the data in the stream
onCompletionRunnable- Not documented.
Throws
java.io.IOException- if the creation of the Media has failed
run
public void run()getPropertyNames
public String[] getPropertyNames()Returns
getPropertyTypes
public Class[] getPropertyTypes()Returns
getPropertyValue
public Object getPropertyValue(String name)Parameters
nameString- the name of the property
Returns
setPropertyValue
public String setPropertyValue(String name, Object value)Parameters
nameString- the name of the property
valueObject- new value for the property
Returns
getPlayIcon
public Image getPlayIcon()Returns
setPlayIcon
public void setPlayIcon(Image playIcon)getPauseIcon
public Image getPauseIcon()Returns
setPauseIcon
public void setPauseIcon(Image pauseIcon)getBackIcon
public Image getBackIcon()Returns
setBackIcon
public void setBackIcon(Image backIcon)getFwdIcon
public Image getFwdIcon()Returns
setFwdIcon
public void setFwdIcon(Image fwdIcon)isAutoplay
public boolean isAutoplay()Returns
setAutoplay
public void setAutoplay(boolean autoplay)Parameters
autoplayboolean- the autoplay to set
isLoop
public boolean isLoop()Returns
setLoop
public void setLoop(boolean loop)Parameters
loopboolean- the loop to set
isOnTopMode
public boolean isOnTopMode()Returns
setOnTopMode
public void setOnTopMode(boolean onTopMode)Parameters
onTopModeboolean- the onTopMode to set
isSeekBar
public boolean isSeekBar()Returns
setSeekBar
public void setSeekBar(boolean seekBar)Parameters
seekBarboolean- the seekBar to set
getSeekBarUIID
public String getSeekBarUIID()Returns
setSeekBarUIID
public void setSeekBarUIID(String seekBarUIID)Parameters
seekBarUIIDString- the seekBarUIID to set
isMaximize
public boolean isMaximize()Returns
setMaximize
public void setMaximize(boolean maximize)Parameters
maximizeboolean- the maximize to set