public class MediaPlayer

  1. Object
  2. Component
  3. Container
  4. 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 IOExceptionSets 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 IOExceptionSets 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

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()
Empty constructor

MediaPlayer

public MediaPlayer(Media video)
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.

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 boolean
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

True if this player uses native video controls.

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()
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

public Media 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

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.

calcPreferredSize

protected Dimension 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

setMaxIcon

public void setMaxIcon(Image maxIcon)
Sets the maximize Button Icon

setDataSource

public void setDataSource(String uri, Runnable onCompletion) throws IOException
Sets the data source of this video player

Parameters

uri String
the uri of the media can start with file://, http:// (can also use rtsp:// although may not be supported on all target platforms)
onCompletion Runnable
Not documented.

Throws

IOException
if creation of media from the given URI has failed

getDataSource

public String getDataSource()
Convenience JavaBean method, see other version of this method

Returns

the data source uri

setDataSource

public void setDataSource(String uri)
Convenience JavaBean method, see other version of this method

Parameters

uri String
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 InputStream
the stream containing the media data
mimeType String
the type of the data in the stream
onCompletion Runnable
Not documented.

Throws

java.io.IOException
if the creation of the Media has failed

run

public void run()

getPropertyNames

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

Returns

the property names allowing mutation

getPropertyTypes

public Class[] getPropertyTypes()
Matches the property names method (see that method for further details).

Returns

the types of the properties

getPropertyValue

public Object getPropertyValue(String name)
Returns the current value of the property name, this method is used by the GUI builder

Parameters

name String
the name of the property

Returns

the value of said property

setPropertyValue

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. Notice that some builtin properties such as “$designMode” might be sent to components to indicate application state.

Parameters

name String
the name of the property
value Object
new value for the property

Returns

error message or null

getPlayIcon

public Image getPlayIcon()

Returns

the playIcon

setPlayIcon

public void setPlayIcon(Image playIcon)
Sets the play Button Icon

getPauseIcon

public Image getPauseIcon()

Returns

the pauseIcon

setPauseIcon

public void setPauseIcon(Image pauseIcon)
Sets the pause Button Icon

getBackIcon

public Image getBackIcon()

Returns

the backIcon

setBackIcon

public void setBackIcon(Image backIcon)
Sets the back Button Icon

getFwdIcon

public Image getFwdIcon()

Returns

the fwdIcon

setFwdIcon

public void setFwdIcon(Image fwdIcon)
Sets the forward Button Icon

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 boolean
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 boolean
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 boolean
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 boolean
the seekBar to set

getSeekBarUIID

public String getSeekBarUIID()
UIID for the seekBar slider

Returns

the seekBarUIID

setSeekBarUIID

public void setSeekBarUIID(String seekBarUIID)
UIID for the seekBar slider

Parameters

seekBarUIID String
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 boolean
the maximize to set