Class MediaPlayer

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class MediaPlayer extends Container

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();
  • 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.

      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 if Media#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 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
      Overrides:
      initComponent in class Component
    • 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:
      deinitialize in class Component
    • 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

      Overrides:
      calcPreferredSize in class Container
    • setMaxIcon

      public void setMaxIcon(Image maxIcon)

      Sets the maximize Button Icon

      Parameters
      • maxIcon
    • setDataSource

      public void setDataSource(String uri, Runnable onCompletion) throws IOException

      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

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

      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

      Overrides:
      getPropertyNames in class Component
    • getPropertyTypes

      public Class[] getPropertyTypes()

      Matches the property names method (see that method for further details).

      Returns

      the types of the properties

      Overrides:
      getPropertyTypes in class Component
    • getPropertyValue

      public Object getPropertyValue(String name)

      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:
      getPropertyValue in class Component
    • 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: the name of the property

      • value: new value for the property

      Returns

      error message or null

      Overrides:
      setPropertyValue in class Component
    • getPlayIcon

      public Image getPlayIcon()
      Returns

      the playIcon

    • setPlayIcon

      public void setPlayIcon(Image playIcon)

      Sets the play Button Icon

      Parameters
      • playIcon
    • getPauseIcon

      public Image getPauseIcon()
      Returns

      the pauseIcon

    • setPauseIcon

      public void setPauseIcon(Image pauseIcon)

      Sets the pause Button Icon

      Parameters
      • pauseIcon
    • getBackIcon

      public Image getBackIcon()
      Returns

      the backIcon

    • setBackIcon

      public void setBackIcon(Image backIcon)

      Sets the back Button Icon

      Parameters
      • backIcon
    • getFwdIcon

      public Image getFwdIcon()
      Returns

      the fwdIcon

    • setFwdIcon

      public void setFwdIcon(Image fwdIcon)

      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

      public String getSeekBarUIID()

      UIID for the seekBar slider

      Returns

      the seekBarUIID

    • setSeekBarUIID

      public void setSeekBarUIID(String seekBarUIID)

      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